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:
देवांश वार्ष्णेय 2023-08-01 13:17:09 +05:30 committed by GitHub
parent 6e80474e62
commit 02a354f3f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 41 deletions

View File

@ -15,13 +15,13 @@
namespace benchmark { namespace benchmark {
namespace { namespace {
// kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta. // 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. // 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. // 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. // We require that all three arrays have the same size.
static_assert(arraysize(kBigSIUnits) == arraysize(kBigIECUnits), 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); const int64_t index = (exponent > 0 ? exponent - 1 : -exponent - 1);
if (index >= kUnitsSize) return ""; if (index >= kUnitsSize) return "";
const char* array = const char* const* array =
(exponent > 0 ? (iec ? kBigIECUnits : kBigSIUnits) : kSmallSIUnits); (exponent > 0 ? (iec ? kBigIECUnits : kBigSIUnits) : kSmallSIUnits);
if (iec) {
return array[index] + std::string("i"); return std::string(array[index]);
}
return std::string(1, array[index]);
} }
std::string ToBinaryStringFullySpecified( std::string ToBinaryStringFullySpecified(double value, int precision,
double value, int precision, Counter::OneK one_k = Counter::kIs1024) { Counter::OneK one_k) {
std::string mantissa; std::string mantissa;
int64_t exponent; int64_t exponent;
ToExponentAndMantissa(value, precision, ToExponentAndMantissa(value, precision,
@ -142,13 +140,6 @@ std::string StrFormatImp(const char* msg, va_list args) {
} // end namespace } // 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) { std::string HumanReadableNumber(double n, Counter::OneK one_k) {
return ToBinaryStringFullySpecified(n, 1, one_k); return ToBinaryStringFullySpecified(n, 1, one_k);
} }

View File

@ -13,9 +13,6 @@
namespace benchmark { namespace benchmark {
BENCHMARK_EXPORT
void AppendHumanReadable(int n, std::string* str);
BENCHMARK_EXPORT BENCHMARK_EXPORT
std::string HumanReadableNumber(double n, Counter::OneK one_k); std::string HumanReadableNumber(double n, Counter::OneK one_k);

View File

@ -1,5 +1,5 @@
//===---------------------------------------------------------------------===// //===---------------------------------------------------------------------===//
// statistics_test - Unit tests for src/statistics.cc // string_util_test - Unit tests for src/string_util.cc
//===---------------------------------------------------------------------===// //===---------------------------------------------------------------------===//
#include <tuple> #include <tuple>
@ -161,25 +161,6 @@ TEST(StringUtilTest, StrSplit) {
std::vector<std::string>({"hello", "there", "is", "more"})); 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< using HumanReadableFixture = ::testing::TestWithParam<
std::tuple<double, benchmark::Counter::OneK, std::string>>; std::tuple<double, benchmark::Counter::OneK, std::string>>;