rogerweb
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_eachandafter_eachhooks 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.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
devonestes
Given that this only takes a few μs, it looks like this is because this falls into the documented exception of functions that are too fast to accurately measure without running then repeatedly. You should probably also see a warning that this function is very fast in the output, right?
rogerweb
That’s what thought too, but no such warning appears and I’m running on Ubuntu and not Windows. I didn’t mention before but I’m running it inside a ExUnit test. Not sure if it might have an impact, though.
devonestes
Running in ExUnit shouldn’t make a difference. Do you have the fast function warning disabled? You can do that when setting up your benchmark.
Either way, I can pretty much guarantee that this happens because that function you’re benchmarking is extremely fast. Can you drop a sleep in there for like 50ms and see what happens?
rogerweb
No, the
:fast_warningis enabled by default and I didn’t set it.I’m benchmarking a function that:
DateTime.utc_now()to get a timestamp;before_each(strings and list of strings) and the timestamp;:mnesia.writeand:mnesia.transaction;As per the metrics in my first post it is fast indeed. Do you think I should benchmark multiple calls to that function instead of individually?
I had done that even before starting this thread, but with 200ms instead of 50ms and in the after_each:
No logger and no sleep
No logger but with Process.sleep(200) in the after_each
I’ll do it in the function being benchmarkd and post the results here.
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.
rogerweb
original function
with Process.sleep(50)
with Process.sleep(50) + Logger in the after_each
The above results show that when the measured function is order of magnitudes slower (from μs to ms) then a simple call to Logger in the hook won’t make a big difference.
Done:
It does have some impact, but it’s not a direct one, otherwise the slower scenario would have resulted in latencies in the order of seconds and not microseconds. The “cpu_heavy” is my naive implementation of fibonacci calculating the first 45 numbers, which takes around 13 seconds.
So yeah, I guess we are all at the same page. Thanks a lot for your time in this thread Devon and for the Benchee library itself.
Cheers!