Counter(): add 'one thousand' param.#657
Conversation
|
❌ Build benchmark 1377 failed (commit 9dd521fc67 by @LebedevRI) |
3d325d6 to
db8dfb4
Compare
|
❌ Build benchmark 1378 failed (commit cb960fbba8 by @LebedevRI) |
db8dfb4 to
05bde77
Compare
|
❌ Build benchmark 1379 failed (commit 0d4a129ac2 by @LebedevRI) |
05bde77 to
44b035e
Compare
|
❌ Build benchmark 1380 failed (commit 28d2e3e708 by @LebedevRI) |
61194b4 to
d4a5af5
Compare
|
✅ Build benchmark 1381 completed (commit d7a05b3067 by @LebedevRI) |
|
✅ Build benchmark 1382 completed (commit a40d39a42e by @LebedevRI) |
|
I haven't looked at this, but my preference would be to encode this info in the type system in some way. Sort of like std::ratio. So maybe make the parameter something similar instead of just taking an integer? |
|
I'm not sure how that would look. Just take |
|
✅ Build benchmark 1383 completed (commit f79a0f2a51 by @LebedevRI) |
|
Ping. |
src/console_reporter.cc
Outdated
| c.first.length()); | ||
| auto const& s = HumanReadableNumber(c.second.value, 1000); | ||
| const double one_k = | ||
| double(c.second.thousand.first) / double(c.second.thousand.second); |
There was a problem hiding this comment.
why is this specified as a pair instead of just a single number (1000 vs 1024)? or even an enum!
There was a problem hiding this comment.
I would personally think just one value is enough (which is what i had in the first commit, d4a5af5),
but #657 (comment) may or may not suggest that something more advanced is needed.
@EricWF ?
There was a problem hiding this comment.
Ah, I think that is suggesting either having an enum with values 1000 and 1024, or to extend Counter to have MegaCounter and MebiCounter variants, which implicitly manage the one_k definition without it being specified.
There was a problem hiding this comment.
Right now i don't have/is not aware of any real use for the one_k not being 1000 or 1024, so enum could work.
It is just that storing enum will take just as much space as storing an int, or a pair of shorts:
https://godbolt.org/z/9Q1gVS
So it isn't obvious to me why we want to avoid doing/allowing the more general thing at the same cost.
There was a problem hiding this comment.
It's just.. weird. Like, why would you define one_k as 2000/2 or 500/PI?
include/benchmark/benchmark.h
Outdated
|
|
||
| double value; | ||
| Flags flags; | ||
| std::pair<int /*Num*/, int /*Denom*/> thousand; |
There was a problem hiding this comment.
Hmm, if it to be an enum, should i just add value k1024 to the Flags enum?
There was a problem hiding this comment.
I think it's an orthogonal feature so i'd add a OneK enum with two values.
There was a problem hiding this comment.
Ok, sounds good.
src/console_reporter.cc
Outdated
| c.first.length()); | ||
| const double one_k = | ||
| double(c.second.thousand.first) / double(c.second.thousand.second); | ||
| const double one_k = [](benchmark::Counter::One_K k) -> double { |
There was a problem hiding this comment.
why not give the enums the values '1000' and '1024' and pass them through (with any necessary cast) to the HumanReadableNumber call?
There was a problem hiding this comment.
There is no real reason not to do it.
I didn't do that because 0 and 1 (which is most likely the current values of these values)
only need one bit, while 1024 needs 11 bits. So if we wanted to pack the size of Counter,
it would likely be simpler with smaller enum values.
I don't think we care about that here, so let's avoid this premature optimization :)
|
❌ Build benchmark 1396 failed (commit 262e146e02 by @LebedevRI) |
Needed for google#654 Custom user counters are quite custom. It is not guaranteed that the user *always* expects for these to have 1k == 1000. If the counter represents bytes/memory/etc, 1k should be 1024. Some bikeshedding points: 1. Is this sufficient, or do we really want to go full on into custom types with names? I think just the '1000' is sufficient for now. 2. Should there be a helper benchmark::Counter::Counter{1000,1024}() static 'constructor' functions, since these two, by far, will be the most used? 3. In the future, we should be somehow encoding this info into JSON.
Simpler is better. If someone comes up with a real reason to need something more advanced, it can be added later on.
3baebbc to
fba1dfb
Compare
|
✅ Build benchmark 1397 completed (commit 506fe68a83 by @LebedevRI) |
include/benchmark/benchmark.h
Outdated
| kAvgIterationsRate = kIsRate | kAvgIterations | ||
| }; | ||
|
|
||
| enum One_K { |
There was a problem hiding this comment.
nit: https://google.github.io/styleguide/cppguide.html#Enumerator_Names
OneK is a better name.
|
Thank you for the review! |
|
✅ Build benchmark 1398 completed (commit 4a40148f12 by @LebedevRI) |
* Counter(): add 'one thousand' param. Needed for google#654 Custom user counters are quite custom. It is not guaranteed that the user *always* expects for these to have 1k == 1000. If the counter represents bytes/memory/etc, 1k should be 1024. Some bikeshedding points: 1. Is this sufficient, or do we really want to go full on into custom types with names? I think just the '1000' is sufficient for now. 2. Should there be a helper benchmark::Counter::Counter{1000,1024}() static 'constructor' functions, since these two, by far, will be the most used? 3. In the future, we should be somehow encoding this info into JSON. * Counter(): use std::pair<> to represent 'one thousand' * Counter(): just use a new enum with two values 1000 vs 1024. Simpler is better. If someone comes up with a real reason to need something more advanced, it can be added later on. * Counter: just store the 1000 or 1024 in the One_K values directly * Counter: s/One_K/OneK/
Needed for #654
Custom user counters are quite custom. It is not guaranteed
that the user always expects for these to have 1k == 1000.
If the counter represents bytes/memory/etc, 1k should be 1024.
Some bikeshedding points:
into custom types with names?
I think just the '1000' is sufficient for now.
static 'constructor' functions, since these two, by far,
will be the most used?