mirror of
https://github.com/google/benchmark.git
synced 2025-04-02 15:40:53 +08:00
revert
This commit is contained in:
parent
53c06366a0
commit
0f5073918c
@ -30,4 +30,4 @@ before_script:
|
||||
script:
|
||||
- cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_FLAGS="-std=${STD}"
|
||||
- make
|
||||
- make test
|
||||
- make CTEST_OUTPUT_ON_FAILURE=1 test
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Copyright 2014 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -216,5 +216,4 @@ bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
|
||||
bool IsFlag(const char* str, const char* flag) {
|
||||
return (ParseFlagValue(str, flag, true) != NULL);
|
||||
}
|
||||
|
||||
} // end namespace benchmark
|
||||
|
@ -73,4 +73,4 @@ MinimalBenchmark& MinimalBenchmark::ThreadPerCpu() {
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // end namespace benchmark
|
||||
} // end namespace benchmark
|
||||
|
@ -103,6 +103,7 @@ class Stat1 {
|
||||
// Return the total weight of this sample set
|
||||
NumType numSamples() const { return numsamples_; }
|
||||
|
||||
// Return the sum of this sample set
|
||||
VType Sum() const { return sum_; }
|
||||
|
||||
// Return the mean of this sample set
|
||||
@ -270,6 +271,7 @@ class Stat1MinMax : public Stat1<VType, NumType> {
|
||||
VType Max() const { return max_; }
|
||||
// Return the minimal value in this sample set
|
||||
VType Min() const { return min_; }
|
||||
|
||||
private:
|
||||
// The - operation makes no sense with Min/Max
|
||||
// unless we keep the full list of values (but we don't)
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Copyright 2014 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -15,9 +15,8 @@
|
||||
#include "sysinfo.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h> // FreeBSD requires this be included before sysctl.h
|
||||
#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
@ -2,12 +2,10 @@
|
||||
#define BENCHMARK_SYSINFO_H_
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
double MyCPUUsage();
|
||||
double ChildrenCPUUsage();
|
||||
int NumCPUs();
|
||||
double CyclesPerSecond();
|
||||
|
||||
} // end namespace benchmark
|
||||
|
||||
#endif // BENCHMARK_SYSINFO_H_
|
||||
|
@ -15,10 +15,12 @@
|
||||
#include "walltime.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
@ -31,8 +33,8 @@ namespace benchmark {
|
||||
namespace walltime {
|
||||
namespace {
|
||||
|
||||
inline bool SplitTimezone(WallTime value, bool local, struct tm* t,
|
||||
double* subsecond) {
|
||||
bool SplitTimezone(WallTime value, bool local, struct tm* t,
|
||||
double* subsecond) {
|
||||
memset(t, 0, sizeof(*t));
|
||||
if ((value < 0) || (value > std::numeric_limits<time_t>::max())) {
|
||||
*subsecond = 0.0;
|
||||
@ -50,14 +52,14 @@ inline bool SplitTimezone(WallTime value, bool local, struct tm* t,
|
||||
} // end anonymous namespace
|
||||
|
||||
|
||||
namespace internal {
|
||||
namespace {
|
||||
|
||||
class WallTimeImp
|
||||
{
|
||||
public:
|
||||
WallTime Now();
|
||||
|
||||
static WallTimeImp & GetWallTimeImp() {
|
||||
static WallTimeImp& GetWallTimeImp() {
|
||||
static WallTimeImp imp;
|
||||
#if __cplusplus >= 201103L
|
||||
static_assert(std::is_trivially_destructible<WallTimeImp>::value,
|
||||
@ -85,7 +87,7 @@ private:
|
||||
return f;
|
||||
}
|
||||
|
||||
WallTime Slow() {
|
||||
WallTime Slow() const {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec + tv.tv_usec * 1e-6;
|
||||
@ -158,12 +160,12 @@ WallTimeImp::WallTimeImp()
|
||||
last_adjust_time_ = static_cast<uint32_t>(uint64_t(base_cycletime_) >> 32);
|
||||
}
|
||||
|
||||
} // end namespace internal
|
||||
} // end anonymous namespace
|
||||
|
||||
|
||||
WallTime Now()
|
||||
{
|
||||
static internal::WallTimeImp& imp = internal::WallTimeImp::GetWallTimeImp();
|
||||
static WallTimeImp& imp = WallTimeImp::GetWallTimeImp();
|
||||
return imp.Now();
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ endmacro(add_gtest_test)
|
||||
# Demonstration executable
|
||||
add_benchmark_test(basic_test)
|
||||
compile_benchmark_test(benchmark_test)
|
||||
add_test(benchmark benchmark_test --benchmark_min_time=0.1 50)
|
||||
add_test(benchmark benchmark_test --benchmark_min_time=0.1 51)
|
||||
add_test(benchmark_filter_simple benchmark_test --benchmark_filter=Calculate 16)
|
||||
add_test(benchmark_filter_suffix benchmark_test --benchmark_filter=Calculate* 16)
|
||||
add_test(benchmark_filter_regex_wildcard benchmark_test --benchmark_filter=.*Calculate.* 16)
|
||||
|
@ -24,11 +24,9 @@
|
||||
|
||||
namespace {
|
||||
|
||||
#ifndef NDEBUG
|
||||
int BENCHMARK_NOINLINE Factorial(uint32_t n) {
|
||||
return (n == 1) ? 1 : n * Factorial(n - 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
double CalculatePi(int depth) {
|
||||
double pi = 0.0;
|
||||
@ -52,7 +50,6 @@ std::vector<int>* test_vector = nullptr;
|
||||
|
||||
} // end namespace
|
||||
|
||||
#ifndef NDEBUG
|
||||
static void BM_Factorial(benchmark::State& state) {
|
||||
int fac_42 = 0;
|
||||
while (state.KeepRunning())
|
||||
@ -61,7 +58,6 @@ static void BM_Factorial(benchmark::State& state) {
|
||||
EXPECT_NE(fac_42, std::numeric_limits<int>::max());
|
||||
}
|
||||
BENCHMARK(BM_Factorial);
|
||||
#endif
|
||||
|
||||
static void BM_CalculatePiRange(benchmark::State& state) {
|
||||
double pi = 0.0;
|
||||
@ -69,15 +65,12 @@ static void BM_CalculatePiRange(benchmark::State& state) {
|
||||
pi = CalculatePi(state.range_x());
|
||||
std::stringstream ss;
|
||||
ss << pi;
|
||||
// Test both overloads of SetLabel to ensure they work.
|
||||
state.SetLabel(ss.str().c_str());
|
||||
state.SetLabel(ss.str());
|
||||
}
|
||||
BENCHMARK_RANGE(BM_CalculatePiRange, 1, 1024 * 1024);
|
||||
|
||||
static void BM_CalculatePi(benchmark::State& state) {
|
||||
static const int depth = 1024;
|
||||
|
||||
double pi BENCHMARK_UNUSED = 0.0;
|
||||
while (state.KeepRunning()) {
|
||||
pi = CalculatePi(depth);
|
||||
@ -152,7 +145,7 @@ static void BM_LongTest(benchmark::State& state) {
|
||||
while (state.KeepRunning())
|
||||
for (int i = 0; i < state.range_x(); ++i)
|
||||
tracker += i;
|
||||
assert(tracker > 1.0);
|
||||
assert(tracker != 0.0);
|
||||
}
|
||||
BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);
|
||||
|
||||
@ -182,9 +175,7 @@ class TestReporter : public benchmark::internal::ConsoleReporter {
|
||||
int main(int argc, const char* argv[]) {
|
||||
benchmark::Initialize(&argc, argv);
|
||||
|
||||
#ifndef NDEBUG
|
||||
assert(Factorial(8) == 40320);
|
||||
#endif
|
||||
assert(CalculatePi(1) == 0.0);
|
||||
|
||||
TestReporter test_reporter;
|
||||
|
Loading…
Reference in New Issue
Block a user