Skip to content

Counter(): add 'one thousand' param.#657

Merged
LebedevRI merged 5 commits intogoogle:masterfrom
LebedevRI:counter-thousand
Aug 29, 2018
Merged

Counter(): add 'one thousand' param.#657
LebedevRI merged 5 commits intogoogle:masterfrom
LebedevRI:counter-thousand

Conversation

@LebedevRI
Copy link
Collaborator

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:

  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.

@AppVeyorBot
Copy link

Build benchmark 1377 failed (commit 9dd521fc67 by @LebedevRI)

@coveralls
Copy link

coveralls commented Aug 19, 2018

Coverage Status

Coverage increased (+0.7%) to 87.635% when pulling 2706e31 on LebedevRI:counter-thousand into d9cab61 on google:master.

@AppVeyorBot
Copy link

Build benchmark 1378 failed (commit cb960fbba8 by @LebedevRI)

@AppVeyorBot
Copy link

Build benchmark 1379 failed (commit 0d4a129ac2 by @LebedevRI)

@AppVeyorBot
Copy link

Build benchmark 1380 failed (commit 28d2e3e708 by @LebedevRI)

@LebedevRI LebedevRI force-pushed the counter-thousand branch 2 times, most recently from 61194b4 to d4a5af5 Compare August 19, 2018 12:06
@AppVeyorBot
Copy link

Build benchmark 1381 completed (commit d7a05b3067 by @LebedevRI)

@LebedevRI LebedevRI requested review from EricWF and dmah42 August 19, 2018 13:10
@AppVeyorBot
Copy link

Build benchmark 1382 completed (commit a40d39a42e by @LebedevRI)

@EricWF
Copy link
Contributor

EricWF commented Aug 19, 2018

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?

@LebedevRI
Copy link
Collaborator Author

I'm not sure how that would look. Just take std::pair<int /*num*/, int /*den*/> ?

@AppVeyorBot
Copy link

Build benchmark 1383 completed (commit f79a0f2a51 by @LebedevRI)

@LebedevRI
Copy link
Collaborator Author

Ping.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this specified as a pair instead of just a single number (1000 vs 1024)? or even an enum!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just.. weird. Like, why would you define one_k as 2000/2 or 500/PI?


double value;
Flags flags;
std::pair<int /*Num*/, int /*Denom*/> thousand;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if it to be an enum, should i just add value k1024 to the Flags enum?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an orthogonal feature so i'd add a OneK enum with two values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not give the enums the values '1000' and '1024' and pass them through (with any necessary cast) to the HumanReadableNumber call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

@AppVeyorBot
Copy link

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.
@AppVeyorBot
Copy link

Build benchmark 1397 completed (commit 506fe68a83 by @LebedevRI)

kAvgIterationsRate = kIsRate | kAvgIterations
};

enum One_K {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LebedevRI
Copy link
Collaborator Author

Thank you for the review!
Awaiting CI completion..

@AppVeyorBot
Copy link

Build benchmark 1398 completed (commit 4a40148f12 by @LebedevRI)

@LebedevRI LebedevRI merged commit caa2fcb into google:master Aug 29, 2018
@LebedevRI LebedevRI deleted the counter-thousand branch August 29, 2018 18:11
JBakamovic pushed a commit to JBakamovic/benchmark that referenced this pull request Dec 6, 2018
* 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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants