mirror of
https://github.com/google/benchmark.git
synced 2024-12-25 20:10:13 +08:00
bug: Inconsistent suffixes console reporter 1009 (#1631)
* removed appendHumanReadable as it was not used anywhere --------- Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
This commit is contained in:
parent
6e80474e62
commit
02a354f3f3
@ -15,13 +15,13 @@
|
||||
|
||||
namespace benchmark {
|
||||
namespace {
|
||||
|
||||
// kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta.
|
||||
const char kBigSIUnits[] = "kMGTPEZY";
|
||||
const char* const kBigSIUnits[] = {"k", "M", "G", "T", "P", "E", "Z", "Y"};
|
||||
// Kibi, Mebi, Gibi, Tebi, Pebi, Exbi, Zebi, Yobi.
|
||||
const char kBigIECUnits[] = "KMGTPEZY";
|
||||
const char* const kBigIECUnits[] = {"Ki", "Mi", "Gi", "Ti",
|
||||
"Pi", "Ei", "Zi", "Yi"};
|
||||
// milli, micro, nano, pico, femto, atto, zepto, yocto.
|
||||
const char kSmallSIUnits[] = "munpfazy";
|
||||
const char* const kSmallSIUnits[] = {"m", "u", "n", "p", "f", "a", "z", "y"};
|
||||
|
||||
// We require that all three arrays have the same size.
|
||||
static_assert(arraysize(kBigSIUnits) == arraysize(kBigIECUnits),
|
||||
@ -92,16 +92,14 @@ std::string ExponentToPrefix(int64_t exponent, bool iec) {
|
||||
const int64_t index = (exponent > 0 ? exponent - 1 : -exponent - 1);
|
||||
if (index >= kUnitsSize) return "";
|
||||
|
||||
const char* array =
|
||||
const char* const* array =
|
||||
(exponent > 0 ? (iec ? kBigIECUnits : kBigSIUnits) : kSmallSIUnits);
|
||||
if (iec) {
|
||||
return array[index] + std::string("i");
|
||||
}
|
||||
return std::string(1, array[index]);
|
||||
|
||||
return std::string(array[index]);
|
||||
}
|
||||
|
||||
std::string ToBinaryStringFullySpecified(
|
||||
double value, int precision, Counter::OneK one_k = Counter::kIs1024) {
|
||||
std::string ToBinaryStringFullySpecified(double value, int precision,
|
||||
Counter::OneK one_k) {
|
||||
std::string mantissa;
|
||||
int64_t exponent;
|
||||
ToExponentAndMantissa(value, precision,
|
||||
@ -142,13 +140,6 @@ std::string StrFormatImp(const char* msg, va_list args) {
|
||||
|
||||
} // end namespace
|
||||
|
||||
void AppendHumanReadable(int n, std::string* str) {
|
||||
std::stringstream ss;
|
||||
// Round down to the nearest SI prefix.
|
||||
ss << ToBinaryStringFullySpecified(n, 0);
|
||||
*str += ss.str();
|
||||
}
|
||||
|
||||
std::string HumanReadableNumber(double n, Counter::OneK one_k) {
|
||||
return ToBinaryStringFullySpecified(n, 1, one_k);
|
||||
}
|
||||
|
@ -13,9 +13,6 @@
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
BENCHMARK_EXPORT
|
||||
void AppendHumanReadable(int n, std::string* str);
|
||||
|
||||
BENCHMARK_EXPORT
|
||||
std::string HumanReadableNumber(double n, Counter::OneK one_k);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//===---------------------------------------------------------------------===//
|
||||
// statistics_test - Unit tests for src/statistics.cc
|
||||
// string_util_test - Unit tests for src/string_util.cc
|
||||
//===---------------------------------------------------------------------===//
|
||||
|
||||
#include <tuple>
|
||||
@ -161,25 +161,6 @@ TEST(StringUtilTest, StrSplit) {
|
||||
std::vector<std::string>({"hello", "there", "is", "more"}));
|
||||
}
|
||||
|
||||
using AppendHumanReadableFixture =
|
||||
::testing::TestWithParam<std::tuple<int, std::string>>;
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
AppendHumanReadableTests, AppendHumanReadableFixture,
|
||||
::testing::Values(std::make_tuple(0, "0"), std::make_tuple(999, "999"),
|
||||
std::make_tuple(1000, "1000"),
|
||||
std::make_tuple(1024, "1Ki"),
|
||||
std::make_tuple(1000 * 1000, "976\\.56.Ki"),
|
||||
std::make_tuple(1024 * 1024, "1Mi"),
|
||||
std::make_tuple(1000 * 1000 * 1000, "953\\.674Mi"),
|
||||
std::make_tuple(1024 * 1024 * 1024, "1Gi")));
|
||||
|
||||
TEST_P(AppendHumanReadableFixture, AppendHumanReadable) {
|
||||
std::string str;
|
||||
benchmark::AppendHumanReadable(std::get<0>(GetParam()), &str);
|
||||
ASSERT_THAT(str, ::testing::MatchesRegex(std::get<1>(GetParam())));
|
||||
}
|
||||
|
||||
using HumanReadableFixture = ::testing::TestWithParam<
|
||||
std::tuple<double, benchmark::Counter::OneK, std::string>>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user