Skip to content

Commit

Permalink
Added PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoKrupitza committed Jun 20, 2023
1 parent 47ce92d commit 6029297
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 65 deletions.
8 changes: 0 additions & 8 deletions src/benchmark_api_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,5 @@ void BenchmarkInstance::Teardown() const {
}
}

/**
* 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);
}

} // namespace internal
} // namespace benchmark
1 change: 0 additions & 1 deletion src/benchmark_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "benchmark/benchmark.h"
#include "commandlineflags.h"
#include "string_util.h"

namespace benchmark {
namespace internal {
Expand Down
11 changes: 10 additions & 1 deletion src/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +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));

// 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) - inclusiveBigThreshhold;
(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;
Expand Down Expand Up @@ -286,6 +291,10 @@ std::string Base10HumanReadableFormat(const int64_t& arg) {
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);
}
Expand Down
6 changes: 0 additions & 6 deletions src/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ using std::stoul; // NOLINT(misc-unused-using-decls)
#endif
// NOLINTEND

/**
* Check whether the given value is a power of two or not.
* @param val the value to check
*/
bool IsPowerOfTwo(const int64_t& val);

/**
* Gets the human readable format for a given base10 value.
* In other words converts 1_000 to 1k, 40_000_000 to 40m etc
Expand Down
107 changes: 58 additions & 49 deletions test/human_readable_gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,64 @@ TEST(HumanReadableTest, base2) {
}
}

TEST(HumanReadableTest, base10) {
{
const auto res = benchmark::Base10HumanReadableFormat(100);
EXPECT_STREQ(res.c_str(), "100");
}
{
const auto res = benchmark::Base10HumanReadableFormat(1000);
EXPECT_STREQ(res.c_str(), "1k");
}
{
const auto res = benchmark::Base10HumanReadableFormat(10000);
EXPECT_STREQ(res.c_str(), "10k");
}
{
const auto res = benchmark::Base10HumanReadableFormat(20000);
EXPECT_STREQ(res.c_str(), "20k");
}
{
const auto res = benchmark::Base10HumanReadableFormat(32000);
EXPECT_STREQ(res.c_str(), "32k");
}
{
const auto res = benchmark::Base10HumanReadableFormat(1000000);
EXPECT_STREQ(res.c_str(), "1M");
}
{
const auto res = benchmark::Base10HumanReadableFormat(42000000);
EXPECT_STREQ(res.c_str(), "42M");
}
{
const auto res = benchmark::Base10HumanReadableFormat(1000000000);
EXPECT_STREQ(res.c_str(), "1B");
}
{
const auto res = benchmark::Base10HumanReadableFormat(4000000000);
EXPECT_STREQ(res.c_str(), "4B");
}
{
const auto res = benchmark::Base10HumanReadableFormat(4200000000);
EXPECT_STREQ(res.c_str(), "4.2B");
}
{
const auto res = benchmark::Base10HumanReadableFormat(40200000);
EXPECT_STREQ(res.c_str(), "40.2M");
}
{
const auto res = benchmark::Base10HumanReadableFormat(4200000000000000000);
EXPECT_STREQ(res.c_str(), "4.2Qi");
}
TEST(HumanReadableTest, base10_100) {
const auto res = benchmark::Base10HumanReadableFormat(100);
EXPECT_STREQ(res.c_str(), "100");
}

TEST(HumanReadableTest, base10_1k) {
const auto res = benchmark::Base10HumanReadableFormat(1000);
EXPECT_STREQ(res.c_str(), "1k");
}

TEST(HumanReadableTest, base10_10k) {
const auto res = benchmark::Base10HumanReadableFormat(10000);
EXPECT_STREQ(res.c_str(), "10k");
}

TEST(HumanReadableTest, base10_20k) {
const auto res = benchmark::Base10HumanReadableFormat(20000);
EXPECT_STREQ(res.c_str(), "20k");
}

TEST(HumanReadableTest, base10_32k) {
const auto res = benchmark::Base10HumanReadableFormat(32000);
EXPECT_STREQ(res.c_str(), "32k");
}

TEST(HumanReadableTest, base10_1M) {
const auto res = benchmark::Base10HumanReadableFormat(1000000);
EXPECT_STREQ(res.c_str(), "1M");
}

TEST(HumanReadableTest, base10_42M) {
const auto res = benchmark::Base10HumanReadableFormat(42000000);
EXPECT_STREQ(res.c_str(), "42M");
}

TEST(HumanReadableTest, base10_1B) {
const auto res = benchmark::Base10HumanReadableFormat(1000000000);
EXPECT_STREQ(res.c_str(), "1B");
}

TEST(HumanReadableTest, base10_4B) {
const auto res = benchmark::Base10HumanReadableFormat(4000000000);
EXPECT_STREQ(res.c_str(), "4B");
}

TEST(HumanReadableTest, base10_4_2B) {
const auto res = benchmark::Base10HumanReadableFormat(4200000000);
EXPECT_STREQ(res.c_str(), "4.2B");
}

TEST(HumanReadableTest, base10_40_2M) {
const auto res = benchmark::Base10HumanReadableFormat(40200000);
EXPECT_STREQ(res.c_str(), "40.2M");
}

TEST(HumanReadableTest, base10_4_2Qi) {
const auto res = benchmark::Base10HumanReadableFormat(4200000000000000000);
EXPECT_STREQ(res.c_str(), "4.2Qi");
}

} // end namespace

0 comments on commit 6029297

Please sign in to comment.