mirror of
https://github.com/google/benchmark.git
synced 2024-12-28 05:20:14 +08:00
d08e7b6056
* Add option to set the default time unit globally This commit introduces the `--benchmark_time_unit={ns|us|ms|s}` command line argument. The argument only affects benchmarks where the time unit is not set explicitly. * Update AUTHORS and CONTRIBUTORS * Test `SetDefaultTimeUnit` * clang format * Use `GetDefaultTimeUnit()` for initializing `TimeUnit` variables * Review fixes * Export functions * Add comment
38 lines
880 B
C++
38 lines
880 B
C++
#include "../include/benchmark/benchmark.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace benchmark {
|
|
namespace internal {
|
|
|
|
namespace {
|
|
|
|
class DummyBenchmark : public Benchmark {
|
|
public:
|
|
DummyBenchmark() : Benchmark("dummy") {}
|
|
virtual void Run(State&) override {}
|
|
};
|
|
|
|
TEST(DefaultTimeUnitTest, TimeUnitIsNotSet) {
|
|
DummyBenchmark benchmark;
|
|
EXPECT_EQ(benchmark.GetTimeUnit(), kNanosecond);
|
|
}
|
|
|
|
TEST(DefaultTimeUnitTest, DefaultIsSet) {
|
|
DummyBenchmark benchmark;
|
|
EXPECT_EQ(benchmark.GetTimeUnit(), kNanosecond);
|
|
SetDefaultTimeUnit(kMillisecond);
|
|
EXPECT_EQ(benchmark.GetTimeUnit(), kMillisecond);
|
|
}
|
|
|
|
TEST(DefaultTimeUnitTest, DefaultAndExplicitUnitIsSet) {
|
|
DummyBenchmark benchmark;
|
|
benchmark.Unit(kMillisecond);
|
|
SetDefaultTimeUnit(kMicrosecond);
|
|
|
|
EXPECT_EQ(benchmark.GetTimeUnit(), kMillisecond);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace internal
|
|
} // namespace benchmark
|