benchmark
benchmark copied to clipboard
[FR] Do not necessarily print "s" or "/s" for custom counters tagged as rate
Is your feature request related to a problem? Please describe. I would like to have a new column in my benchmark report presenting the number of operations per dollar. I have a constant value that I know, which is the cost per second. The calculation I want in that column is given by the formula:
number_of_iterations / (cost_per_second * total_execution_time_in_seconds)
I think I can obtain the number of iterations using the iterations()
function in the state object, but I couldn't find a way to recover the total execution time. The only way I found to do that calculation is by adding a new counter with 1 / cost_per_second
and tag it as benchmark::Counter::kIsIterationInvariantRate
state.counters["Throughput"] = benchmark::Counter(
1 / cost_per_second,
benchmark::Counter::kIsIterationInvariantRate
);
This will multiply 1 / cost_per_second
by number_of_iterations / total_execution_time_in_seconds
and will give me the exact value I want. However, since I'm using a kIsRate
variant, it will always append "/s" to that value when I print the report in the console. This is wrong. The unit, in this case, would be "OP/$".
Describe the solution you'd like
Implement a new element in the enum kHasNoUnit
and don't append the "/s" in case it is in use.
state.counters["Throughput"] = benchmark::Counter(
1 / cost_per_second,
benchmark::Counter::kIsIterationInvariantRate | benchmark::Counter::kHasNoUnit
);
Describe alternatives you've considered Another option would be to simply enable the user to define a custom unit to the counter. In this case, I would set "OP/$".