-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --benchmark_human_readable
flag
#1607
base: main
Are you sure you want to change the base?
Add --benchmark_human_readable
flag
#1607
Conversation
"test/human_readable_formatting_test.cc:34: CheckRun: Check `name == run.benchmark_name()' failed. expected BM_base_two_args/2^1 got BM_base_two_args/2" test is failing |
e44d95f
to
47ce92d
Compare
I squashed all the commits into a single one such that there is only one commit to merge. |
thanks.. i generally "squash and merge" anyway, but this means less editing of commit messages for me :D |
src/string_util.cc
Outdated
@@ -44,7 +51,8 @@ void ToExponentAndMantissa(double val, double thresh, int precision, | |||
// in 'precision' digits. | |||
const double adjusted_threshold = | |||
std::max(thresh, 1.0 / std::pow(10.0, precision)); | |||
const double big_threshold = adjusted_threshold * one_k; | |||
const double big_threshold = | |||
(adjusted_threshold * one_k) - inclusiveBigThreshhold; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you appear to be subtracting a boolean from a double.. that's surprising and maybe you could make this explicit instead of relying on an implicit conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this neat little hack to make the code a litte bit more concise. But I can make it more explicit and add a little bit of docu why this trick is needed.
src/string_util.h
Outdated
* Check whether the given value is a power of two or not. | ||
* @param val the value to check | ||
*/ | ||
bool IsPowerOfTwo(const int64_t& val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these need to be exposed in the API? i think only FormatHumanReadable
is accessed by a different implementation file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this method doesnt need to be exposed. Exposing Base10 and Base2 is needed for tests and may be needed by other functions in the future.
6029297
to
2d68daa
Compare
Allows used to add a command line flag called `--benchmark_human_readable`. By adding this flag the arguments passed to benchmarks are formatted in a human friendly format. This means that numbers that are the power of 2 are formatted as `2^x` (e.g., 64 will be `2^6`). For numbers that are the power of 10 a different formatting style is used. Numbers 0-999 no formatting is used. For numbers 1000-999999 the format `k` is used (e.g., `32000` -> `32k`). This also works for millions, billions, trillions, ... For numbers greater than septillions no special formatting is used. The design is rather simple allowing to by easily extendable. Closes: google#1006
80e16d9
to
1b8158f
Compare
im not a big fan of "human readable format". Id consider binary output to be not human readable but not base10 numbers. Asked chatgpt what it "thinks" about that and here is the answer: |
i think it's a pretty well-defined name at this point.
or
|
@@ -1,6 +1,8 @@ | |||
#ifndef BENCHMARK_API_INTERNAL_H | |||
#define BENCHMARK_API_INTERNAL_H | |||
|
|||
#include <array> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still seeing these two headers. i'm sure they don't need to be added and i'd rather minimise any dependencies.
@@ -32,7 +38,8 @@ static const int64_t kUnitsSize = arraysize(kBigSIUnits); | |||
|
|||
void ToExponentAndMantissa(double val, double thresh, int precision, | |||
double one_k, std::string* mantissa, | |||
int64_t* exponent) { | |||
int64_t* exponent, | |||
bool inclusiveBigThreshhold = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we only set this to true when we're doing base-10. it might be worth having a comment why this is necessary for base-10. or even better, renaming the variable to indicate that directly.
Allows used to add a command line flag called
--benchmark_human_readable
. By adding this flag the arguments passed to benchmarks are formated in a human friendly format. This means that numbers that are the power of 2 are formatted as2^x
(e.g., 64 will be2^6
). For numbers that are the power of 10 a different formatting style is used. Numbers 0-999 no formatting is used. For numbers 1000-999999 the formatk
is used (e.g.,32000
->32k
). This also works for millions and billions. For numbers greater than 999 billion no special formatting is used.The design is rather simple allowing to by easily extendable.
Closes: #1006