google / google/benchmark

[FR] Determine suitable time unit for a benchmark if none is set explicitly

Open
#1,405 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
10.4k
Forks
1.8k
Avg merge
2d 4h
Merged PRs (30d)
8

Description

**Is your feature request related to a problem? Please describe.**
Setting a suitable time unit for a specific benchmark is sometimes tedious when the machine the benchmark is developed on is not the only machine the benchmark is run on. E.g imagine a company where code is written for high performant server cpus as well as for weak embedded cpus. Furthermore if some code is sped up for one reason or another the benchmark time unit for this code might not get adapted....
This may end up in results which are hard to interpret on a certain machine because the set time unit is too low and the reported time is as very large number. Furthermore I would argue, that if the set time unit is way to small (often by default --> ns) the results pretend to be very precise while they aren't. Imagine a benchmark which takes a billion ns. This benchmark will print results down to a ns.

**Describe the solution you'd like**
I would like libbenchmark to figure out a suitable time uint itself (not for benchmarks which have set their unit specifically or through the global flag). This could be done by e.g running the benchmark and then choose a time unit in which the result is precise down to 0.1% of the total runtime. E.g running a benchmark which takes 10051ms should be reported as 10.05s.
However for benchmarks which run for e.g different ranges the time unit should be choosen the same for all.

**Describe alternatives you've considered**
I am not aware of any.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.