-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add optional ms time unit for console reporter #192
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
Conversation
Some benchmarks may run a few milliseconds which makes it kind of hard to visually compare, since the currently only available nanoseconds numbers can get very large in this case. Therefore this commit adds an optional command line flag --benchmark_time_unit which lets the user choose between ns and ms time units for displaying the mean execution time.
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
CLAs look good, thanks! |
src/console_reporter.cc
Outdated
| } | ||
|
|
||
| double const multiplier = 1e9; // nano second multiplier | ||
| double const multiplier = time_unit_ == "ns" ? 1e9 : 1e3; // nano second or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we take pains to make other values human readable. could we do the same here?
ie, instead of a flag, can we add the unit suffix to the output and automatically detect if the value should be ns, us, ms, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, interesting. Say, for example the measured values are above a certain number the unit should switch to the next greater one (from ns -> us -> ms -> s)? The unit in the header row would be removed then. I would propose a time unit range from nanoseconds up to seconds (we can safely ditch the planck time here, for sure :-) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right. that's essentially what we do with the values that go into the benchmark name.
it might make at-a-glance comparison a little more awkward if a single benchmark jumps between units. i'm not sure what's best.
i do know that flags are clumsy :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed.
In order to stay backwards compatible, I'd suggest to keep the default behaviour the way it is (all values in ns). If there shouldn't be another commandline flag, we could just add more rows for ms and seconds besides the already existing ns row. In this case at-a-glance comparisons would still be possible for one unit. Otherwise I could change the commandline flag (as well as the implementation) to move units directly to the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think anyone is parsing the console output so just changing it should be fine.
we have csv and json that is more readily parseable, and shouldn't be affected by this change.
|
Would it make sense to specify the unit in the benchmark registration itself? Something like: I'd say that when you write a benchmark you have a reasonable idea of the time it will take. The notion of having the reporting magically decide what order of magnitude works best worries me: in the above example it would be very inconvenient if the run for |
|
That's an interesting compromise. I have a strong preference for not requiring configuration, so i'd refactor things to run all the runs for a benchmark arg set and then decide which unit to present for the set. However, if @NewProggie wants to add this as an option and see how it plays out, i'd love to see it. |
|
Gathering all times for all the runs before setting a time unit and reporting it would be more work I guess. Furthermore one would not see any measured times before the last run for a benchmark suite has finished (which might take a longer time). This is unfortunate. |
src/console_reporter.cc
Outdated
| result.report_label.c_str()); | ||
| } | ||
|
|
||
| TimeUnitMultiplier ConsoleReporter::getTimeUnitAndMultiplier(TimeUnit unit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i've asked a benchmark to report in ms, it should be reported in ms no matter which reporter I use.
as such, this can be moved to BenchmarkReporter and called from each of csv, json, and console reporters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is unclear to me, since csv and json reporter currently don't display the time unit. Nevertheless I moved the function to BenchmarkReporter as you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, but they should now scale appropriately given the user has requested a particular time scale.
they should maybe have a field for the time unit added too...
|
By the way: I've noticed that the code formatting is inconsistent in several areas, but didn't want to pollute this pull request with reformatting. I could provide an appropriate clang-format configuration (basically: use Style: Google) and open another pull request for this? |
test/CMakeLists.txt
Outdated
| # Enable the tests | ||
|
|
||
| # Allow the source files to find headers in src/ | ||
| include_directories(${PROJECT_SOURCE_DIR}/src) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you shouldn't need this. the only extra thing here is the time unit which is already in include/benchmark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, yes. I was using SleepForMilliseconds in my test in order to get appropriate timings for each time unit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right. it's a shame to break the abstraction here and have tests that seem to rely on internals. could you add a comment to the CMakeLists.txt explaining why it's necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is unfortunate. Maybe we should use a different approach here, such as a bad implemented fibonacci function which generates the work load and ditch the SleepForMilliseconds inside the test alltogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whatever you want to do is fine. sleeping is ok, as long as we're clear in the cmake config why we're relying on src. i'd hate for users to read that as an example and think they need internals for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #199
the benchmark test there uses std::this_thread::sleep_for which doesn't require pulling from src.
|
Thank you! |
|
Thanks as well. I've learned some new things along the way ;-) |
Some benchmarks may run a few milliseconds which makes it kind of hard to visually compare, since the currently only available nanoseconds numbers can get very large in this case. Therefore this commit adds an optional command line flag
--benchmark_time_unitwhich lets the user choose between ns and ms time units for displaying the mean execution time.