From 02a354f3f323ae8256948e1dc77ddcb1dfc297da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=A6=E0=A5=87=E0=A4=B5=E0=A4=BE=E0=A4=82=E0=A4=B6=20?= =?UTF-8?q?=E0=A4=B5=E0=A4=BE=E0=A4=B0=E0=A5=8D=E0=A4=B7=E0=A5=8D=E0=A4=A3?= =?UTF-8?q?=E0=A5=87=E0=A4=AF?= Date: Tue, 1 Aug 2023 13:17:09 +0530 Subject: [PATCH] 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> --- src/string_util.cc | 27 +++++++++------------------ src/string_util.h | 3 --- test/string_util_gtest.cc | 21 +-------------------- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/string_util.cc b/src/string_util.cc index 2dc7b18650..c69e40a813 100644 --- a/src/string_util.cc +++ b/src/string_util.cc @@ -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); } diff --git a/src/string_util.h b/src/string_util.h index b05281b9b4..731aa2c04c 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -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); diff --git a/test/string_util_gtest.cc b/test/string_util_gtest.cc index 7cf5749832..67b4bc0c24 100644 --- a/test/string_util_gtest.cc +++ b/test/string_util_gtest.cc @@ -1,5 +1,5 @@ //===---------------------------------------------------------------------===// -// statistics_test - Unit tests for src/statistics.cc +// string_util_test - Unit tests for src/string_util.cc //===---------------------------------------------------------------------===// #include @@ -161,25 +161,6 @@ TEST(StringUtilTest, StrSplit) { std::vector({"hello", "there", "is", "more"})); } -using AppendHumanReadableFixture = - ::testing::TestWithParam>; - -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>;