rogerweb

rogerweb

Benchee after_each hook impact on measurements

Hi,

The benchee documentation states:

Of course, hooks are not included in the measurements (…) Sadly there is the notable exception of too_fast_functions (…). As we need to measure their repeated invocations to get halfway good measurements before_each and after_each hooks are included there. However, to the best of our knowledge this should only ever happen on Windows (because of the bad run time measurement accuracy).

However, if I simply add a call to Logger.debug(...) to my after_each function the measurements are greatly impacted:

Without the Logger

Name                   ips        average  deviation         median         99th %
insert_agent       40.26 K       24.84 μs    ±36.17%       22.57 μs       49.31 μs
insert_agent       44.80 K       22.32 μs    ±26.08%       21.03 μs       41.00 μs
insert_agent       43.39 K       23.05 μs    ±31.96%       21.38 μs       42.45 μs

With the Logger

insert_agent       17.01 K       58.80 μs   ±353.56%       42.42 μs      292.90 μs
insert_agent       17.32 K       57.75 μs   ±249.72%       42.66 μs      321.68 μs
insert_agent       17.72 K       56.43 μs   ±246.62%       42.46 μs      284.70 μs

(showing 3 repeated executions of each scenario just to show that it is repeatable)

Any idea what I might be missing?

I’m running benchee 1.0.1 and the setup is:

Operating System: Linux
CPU Information: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Number of Available Cores: 4
Available memory: 7.68 GB
Elixir 1.12.2
Erlang 24.1.3

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 0 ns
parallel: 1
inputs: default
Estimated total run time: 7 s

Thanks for any clarification.

Marked As Solved

devonestes

devonestes

Ok, that’s really clear now. It makes an impact in your measurements not because the computation happening in the hooks is being measured, but because what you’re doing in those hooks is creating work that is likely being performed asynchronously by the VM during the execution of further runs of the function being benchmarked. This logging fits that, since logging is async. If you want to test that for sure, do something like calculate a ton of fibbonaci numbers in a hook (since that doesn’t do anything outside the active process) to see that it shouldn’t affect the benchmark.

Unfortunately, benchmarking on a VM that is made for parallelism like the BEAM comes with caveats like this sometimes.

Where Next?

Popular in Questions Top

New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36432 110
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement