Skip to content

Commit

Permalink
bug: Inconsistent suffixes console reporter 1009 (#1631)
Browse files Browse the repository at this point in the history
* removed appendHumanReadable as it was not used anywhere

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
  • Loading branch information
varshneydevansh and dmah42 committed Aug 1, 2023
1 parent 6e80474 commit 02a354f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 41 deletions.
27 changes: 9 additions & 18 deletions src/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions src/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
21 changes: 1 addition & 20 deletions test/string_util_gtest.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//===---------------------------------------------------------------------===//
// statistics_test - Unit tests for src/statistics.cc
// string_util_test - Unit tests for src/string_util.cc
//===---------------------------------------------------------------------===//

#include <tuple>
Expand Down Expand Up @@ -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>>;

Expand Down

0 comments on commit 02a354f

Please sign in to comment.