-
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
Open
DiegoKrupitza
wants to merge
1
commit into
google:main
Choose a base branch
from
DiegoKrupitza:feat/1006_human_readable_format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ Colin Braley <[email protected]> | |
Daniel Harvey <[email protected]> | ||
David Coeurjolly <[email protected]> | ||
Deniz Evrenci <[email protected]> | ||
Dirac Research | ||
Dirac Research | ||
Diego Krupitza <[email protected]> | ||
Dominik Czarnota <[email protected]> | ||
Dominik Korman <[email protected]> | ||
Donald Aingworth <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ Cyrille Faucheux <[email protected]> | |
Daniel Harvey <[email protected]> | ||
David Coeurjolly <[email protected]> | ||
Deniz Evrenci <[email protected]> | ||
Diego Krupitza <[email protected]> | ||
Dominic Hamon <[email protected]> <[email protected]> | ||
Dominik Czarnota <[email protected]> | ||
Dominik Korman <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include "string_util.h" | ||
|
||
#include <array> | ||
#include <cinttypes> | ||
#ifdef BENCHMARK_STL_ANDROID_GNUSTL | ||
#include <cerrno> | ||
#endif | ||
|
@@ -15,6 +16,11 @@ | |
namespace benchmark { | ||
namespace { | ||
|
||
// Thousands, Millions, Billions, Trillions, Quadrillions, Quintillions, | ||
// Sextillions, Septillions. | ||
const std::array<std::string, 8> base10Units = {"k", "M", "B", "T", | ||
"Q", "Qi", "Sx", "Sp"}; | ||
|
||
// kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta. | ||
const char kBigSIUnits[] = "kMGTPEZY"; | ||
// Kibi, Mebi, Gibi, Tebi, Pebi, Exbi, Zebi, Yobi. | ||
|
@@ -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 commentThe 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. |
||
std::stringstream mantissa_stream; | ||
|
||
if (val < 0) { | ||
|
@@ -44,7 +51,13 @@ 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; | ||
|
||
// used to make the big_threshold inclusive or not. By subtracting 1 from | ||
// big_threshold we make the range inclusive | ||
const double big_threshold_slide = inclusiveBigThreshhold ? 1.0 : 0.0; | ||
const double big_threshold = | ||
(adjusted_threshold * one_k) - big_threshold_slide; | ||
|
||
const double small_threshold = adjusted_threshold; | ||
// Values in ]simple_threshold,small_threshold[ will be printed as-is | ||
const double simple_threshold = 0.01; | ||
|
@@ -262,4 +275,39 @@ double stod(const std::string& str, size_t* pos) { | |
} | ||
#endif | ||
|
||
std::string ExponentToBase10Prefix(int64_t exponent) { | ||
if (exponent == 0) return ""; | ||
|
||
const int64_t index = (exponent > 0 ? exponent - 1 : -exponent - 1); | ||
if (index >= kUnitsSize) return ""; | ||
|
||
return base10Units[index]; | ||
} | ||
|
||
std::string Base10HumanReadableFormat(const int64_t& arg) { | ||
std::string mantissa; | ||
int64_t exponent; | ||
ToExponentAndMantissa(arg, 1, 1, 1000, &mantissa, &exponent, true); | ||
return mantissa + ExponentToBase10Prefix(exponent); | ||
} | ||
|
||
/** | ||
* Check whether the given value is a power of two or not. | ||
* @param val the value to check | ||
*/ | ||
bool IsPowerOfTwo(const int64_t& val) { | ||
return (val & (val - 1)) == 0 && (val > 1); | ||
} | ||
|
||
std::string Base2HumanReadableFormat(const int64_t& arg) { | ||
return StrFormat("2^%.0f", std::log2(arg)); | ||
} | ||
|
||
std::string FormatHumanReadable(const int64_t& arg) { | ||
if (IsPowerOfTwo(arg)) { | ||
return Base2HumanReadableFormat(arg); | ||
} | ||
return Base10HumanReadableFormat(arg); | ||
} | ||
|
||
} // end namespace benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.