martinus / nanobench

Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20
https://nanobench.ankerl.com
MIT License
1.43k stars 82 forks source link

Q: How to print milliseconds using an output template? #107

Open lprc opened 7 months ago

lprc commented 7 months ago

I'm using the following very simple template for CSV-output, which works fine (stripped down from the CSV-template that nanobench comes with).

"name";"elapsed";"unit"
{{#result}}"{{name}}";{{minimum(elapsed)}};"{{unit}}"
{{/result}}

However I'd like to print elapsed in milliseconds instead of seconds. Is that possible using a template?

(Plus I don't understand why unit prints "op" instead of "seconds".)

I would also be fine with an alternative solution. E.g. before I used the following to get the minimum time over all measurements.

// Get minimum of all epochs in ms
double minTime = 1000000;
for (auto r : bench.results())
    if (r.minimum(ankerl::nanobench::Result::Measure::elapsed) < minTime)
        minTime = r.minimum(ankerl::nanobench::Result::Measure::elapsed) * 1000.0;

However, I'd also like to selectively get the minimum time per name, for which I didn't find an intuitive solution yet. The upper one already feels a bit hacky since there is no example or documentation on this.

Thank you!

0xB10C commented 6 months ago

I've run into a similar issue, though in my case it would be nice to render nanosecond instead of seconds for https://github.com/bitcoin/bitcoin/issues/27284#issuecomment-2042950381