Skip to content

Commit 6029297

Browse files
committed
Added PR feedback
1 parent 47ce92d commit 6029297

5 files changed

Lines changed: 68 additions & 65 deletions

File tree

src/benchmark_api_internal.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,5 @@ void BenchmarkInstance::Teardown() const {
124124
}
125125
}
126126

127-
/**
128-
* Check whether the given value is a power of two or not.
129-
* @param val the value to check
130-
*/
131-
bool IsPowerOfTwo(const int64_t& val) {
132-
return (val & (val - 1)) == 0 && (val > 1);
133-
}
134-
135127
} // namespace internal
136128
} // namespace benchmark

src/benchmark_api_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "benchmark/benchmark.h"
1414
#include "commandlineflags.h"
15-
#include "string_util.h"
1615

1716
namespace benchmark {
1817
namespace internal {

src/string_util.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ void ToExponentAndMantissa(double val, double thresh, int precision,
5151
// in 'precision' digits.
5252
const double adjusted_threshold =
5353
std::max(thresh, 1.0 / std::pow(10.0, precision));
54+
55+
// used to make the big_threshold inclusive or not. By subtracting 1 from
56+
// big_threshold we make the range inclusive
57+
const double big_threshold_slide = inclusiveBigThreshhold ? 1.0 : 0.0;
5458
const double big_threshold =
55-
(adjusted_threshold * one_k) - inclusiveBigThreshhold;
59+
(adjusted_threshold * one_k) - big_threshold_slide;
60+
5661
const double small_threshold = adjusted_threshold;
5762
// Values in ]simple_threshold,small_threshold[ will be printed as-is
5863
const double simple_threshold = 0.01;
@@ -286,6 +291,10 @@ std::string Base10HumanReadableFormat(const int64_t& arg) {
286291
return mantissa + ExponentToBase10Prefix(exponent);
287292
}
288293

294+
/**
295+
* Check whether the given value is a power of two or not.
296+
* @param val the value to check
297+
*/
289298
bool IsPowerOfTwo(const int64_t& val) {
290299
return (val & (val - 1)) == 0 && (val > 1);
291300
}

src/string_util.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ using std::stoul; // NOLINT(misc-unused-using-decls)
6565
#endif
6666
// NOLINTEND
6767

68-
/**
69-
* Check whether the given value is a power of two or not.
70-
* @param val the value to check
71-
*/
72-
bool IsPowerOfTwo(const int64_t& val);
73-
7468
/**
7569
* Gets the human readable format for a given base10 value.
7670
* In other words converts 1_000 to 1k, 40_000_000 to 40m etc

test/human_readable_gtest.cc

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,64 @@ TEST(HumanReadableTest, base2) {
1616
}
1717
}
1818

19-
TEST(HumanReadableTest, base10) {
20-
{
21-
const auto res = benchmark::Base10HumanReadableFormat(100);
22-
EXPECT_STREQ(res.c_str(), "100");
23-
}
24-
{
25-
const auto res = benchmark::Base10HumanReadableFormat(1000);
26-
EXPECT_STREQ(res.c_str(), "1k");
27-
}
28-
{
29-
const auto res = benchmark::Base10HumanReadableFormat(10000);
30-
EXPECT_STREQ(res.c_str(), "10k");
31-
}
32-
{
33-
const auto res = benchmark::Base10HumanReadableFormat(20000);
34-
EXPECT_STREQ(res.c_str(), "20k");
35-
}
36-
{
37-
const auto res = benchmark::Base10HumanReadableFormat(32000);
38-
EXPECT_STREQ(res.c_str(), "32k");
39-
}
40-
{
41-
const auto res = benchmark::Base10HumanReadableFormat(1000000);
42-
EXPECT_STREQ(res.c_str(), "1M");
43-
}
44-
{
45-
const auto res = benchmark::Base10HumanReadableFormat(42000000);
46-
EXPECT_STREQ(res.c_str(), "42M");
47-
}
48-
{
49-
const auto res = benchmark::Base10HumanReadableFormat(1000000000);
50-
EXPECT_STREQ(res.c_str(), "1B");
51-
}
52-
{
53-
const auto res = benchmark::Base10HumanReadableFormat(4000000000);
54-
EXPECT_STREQ(res.c_str(), "4B");
55-
}
56-
{
57-
const auto res = benchmark::Base10HumanReadableFormat(4200000000);
58-
EXPECT_STREQ(res.c_str(), "4.2B");
59-
}
60-
{
61-
const auto res = benchmark::Base10HumanReadableFormat(40200000);
62-
EXPECT_STREQ(res.c_str(), "40.2M");
63-
}
64-
{
65-
const auto res = benchmark::Base10HumanReadableFormat(4200000000000000000);
66-
EXPECT_STREQ(res.c_str(), "4.2Qi");
67-
}
19+
TEST(HumanReadableTest, base10_100) {
20+
const auto res = benchmark::Base10HumanReadableFormat(100);
21+
EXPECT_STREQ(res.c_str(), "100");
22+
}
23+
24+
TEST(HumanReadableTest, base10_1k) {
25+
const auto res = benchmark::Base10HumanReadableFormat(1000);
26+
EXPECT_STREQ(res.c_str(), "1k");
27+
}
28+
29+
TEST(HumanReadableTest, base10_10k) {
30+
const auto res = benchmark::Base10HumanReadableFormat(10000);
31+
EXPECT_STREQ(res.c_str(), "10k");
32+
}
33+
34+
TEST(HumanReadableTest, base10_20k) {
35+
const auto res = benchmark::Base10HumanReadableFormat(20000);
36+
EXPECT_STREQ(res.c_str(), "20k");
37+
}
38+
39+
TEST(HumanReadableTest, base10_32k) {
40+
const auto res = benchmark::Base10HumanReadableFormat(32000);
41+
EXPECT_STREQ(res.c_str(), "32k");
42+
}
43+
44+
TEST(HumanReadableTest, base10_1M) {
45+
const auto res = benchmark::Base10HumanReadableFormat(1000000);
46+
EXPECT_STREQ(res.c_str(), "1M");
47+
}
48+
49+
TEST(HumanReadableTest, base10_42M) {
50+
const auto res = benchmark::Base10HumanReadableFormat(42000000);
51+
EXPECT_STREQ(res.c_str(), "42M");
52+
}
53+
54+
TEST(HumanReadableTest, base10_1B) {
55+
const auto res = benchmark::Base10HumanReadableFormat(1000000000);
56+
EXPECT_STREQ(res.c_str(), "1B");
57+
}
58+
59+
TEST(HumanReadableTest, base10_4B) {
60+
const auto res = benchmark::Base10HumanReadableFormat(4000000000);
61+
EXPECT_STREQ(res.c_str(), "4B");
62+
}
63+
64+
TEST(HumanReadableTest, base10_4_2B) {
65+
const auto res = benchmark::Base10HumanReadableFormat(4200000000);
66+
EXPECT_STREQ(res.c_str(), "4.2B");
67+
}
68+
69+
TEST(HumanReadableTest, base10_40_2M) {
70+
const auto res = benchmark::Base10HumanReadableFormat(40200000);
71+
EXPECT_STREQ(res.c_str(), "40.2M");
72+
}
73+
74+
TEST(HumanReadableTest, base10_4_2Qi) {
75+
const auto res = benchmark::Base10HumanReadableFormat(4200000000000000000);
76+
EXPECT_STREQ(res.c_str(), "4.2Qi");
6877
}
6978

7079
} // end namespace

0 commit comments

Comments
 (0)