google / google/benchmark

[FR] Do not necessarily print "s" or "/s" for custom counters tagged as rate

Open
#1,588 0 comments 1 reaction 0 assignees View on GitHub
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.**
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`

```c++
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"](https://github.com/google/benchmark/blob/bc5651e54a7e178ca6b1e27e469a9be19cfa62c4/src/console_reporter.cc#L161) 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.

```c++
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/$".

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.