-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd performance characteristics of using inputs vs. not using inputs #282
Comments
Run time histograms, with input: without input: Full HTML reports: with input: without input: |
If anyone looks at this and says "SHOW ME THE CODE" - it's really not that much different, you can check https://github.com/bencheeorg/benchee/blob/master/lib/benchee/benchmark/runner.ex The relevant parts that take the run time measurement: def collect(
scenario = %Scenario{function: function},
scenario_context = %ScenarioContext{
num_iterations: 1
},
collector
) do
new_input = Hooks.run_before_each(scenario, scenario_context)
function = main_function(function, new_input)
{measurement, return_value} = collector.collect(function)
Hooks.run_after_each(return_value, scenario, scenario_context)
measurement
end
def main_function(function, @no_input), do: function
def main_function(function, input), do: fn -> function.(input) end So code wise the only difference that I can think of is Maybe it's that the input isn't local to the function and hence other optimizations can kick in? @michalmuskala |
I know I have my own level of fun talking to myself here, something that just came to my mind: With |
Based on those performance characteristics, it looks like maybe garbage collection is triggered with the inputs version? Want to measure memory usage as well on there and see what the difference is? It should be the exact same, but if it’s not then that’s a good clue. |
memory consumption is measured in the HTML samples I posted, and its exactly the same - was also my hope that this would show something. Maybe amount of GCs could still be different? Dunno. |
Reworking the README I came upon an interesting performance difference. So let's do our standard example first:
results in:
Now let's switch it up slightly and hand the list in through
inputs
:results in:
All of a sudden average and median for
map.flatten
are a lot better (~200μs better). The performance offlat_map
stays about the same 🤷♀️I tried this multiple times. It's no coincedence, the question is why - if anything I'd have thought that the version without
inputs
would be faster not the other way around.Trying to summon @michalmuskala who maybe has some compiler input 🤷♂️
The text was updated successfully, but these errors were encountered: