Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
4b3bbe34
Commit
4b3bbe34
authored
Mar 09, 2015
by
Eric
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #84 from google/upgrade-step2
Step two towards merging timer changes.
parents
61f05062
d20cdf19
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
235 additions
and
101 deletions
+235
-101
CMakeLists.txt
src/CMakeLists.txt
+1
-1
benchmark.cc
src/benchmark.cc
+13
-19
check.h
src/check.h
+45
-5
log.cc
src/log.cc
+41
-0
log.h
src/log.h
+29
-0
walltime.cc
src/walltime.cc
+105
-68
walltime.h
src/walltime.h
+0
-1
CMakeLists.txt
test/CMakeLists.txt
+1
-1
benchmark_test.cc
test/benchmark_test.cc
+0
-6
No files found.
src/CMakeLists.txt
View file @
4b3bbe34
...
@@ -3,7 +3,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src)
...
@@ -3,7 +3,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src)
# Define the source files
# Define the source files
set
(
SOURCE_FILES
"benchmark.cc"
"colorprint.cc"
"commandlineflags.cc"
set
(
SOURCE_FILES
"benchmark.cc"
"colorprint.cc"
"commandlineflags.cc"
"sleep.cc"
"sysinfo.cc"
"walltime.cc"
)
"
log.cc"
"
sleep.cc"
"sysinfo.cc"
"walltime.cc"
)
# Determine the correct regular expression engine to use
# Determine the correct regular expression engine to use
if
(
HAVE_STD_REGEX
)
if
(
HAVE_STD_REGEX
)
set
(
RE_FILES
"re_std.cc"
)
set
(
RE_FILES
"re_std.cc"
)
...
...
src/benchmark.cc
View file @
4b3bbe34
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "colorprint.h"
#include "colorprint.h"
#include "commandlineflags.h"
#include "commandlineflags.h"
#include "internal_macros.h"
#include "internal_macros.h"
#include "log.h"
#include "re.h"
#include "re.h"
#include "sleep.h"
#include "sleep.h"
#include "stat.h"
#include "stat.h"
...
@@ -382,9 +383,7 @@ void BenchmarkFamilies::FindBenchmarks(
...
@@ -382,9 +383,7 @@ void BenchmarkFamilies::FindBenchmarks(
// Match against filter.
// Match against filter.
if
(
!
re
.
Match
(
family
->
name_
))
{
if
(
!
re
.
Match
(
family
->
name_
))
{
#ifdef DEBUG
VLOG
(
1
)
<<
"Skipping "
<<
family
->
name_
<<
"
\n
"
;
std
::
cout
<<
"Skipping "
<<
family
->
name_
<<
"
\n
"
;
#endif
continue
;
continue
;
}
}
...
@@ -845,9 +844,7 @@ void Benchmark::MeasureOverhead() {
...
@@ -845,9 +844,7 @@ void Benchmark::MeasureOverhead() {
}
}
overhead
=
state
.
runs
[
0
].
real_accumulated_time
/
overhead
=
state
.
runs
[
0
].
real_accumulated_time
/
static_cast
<
double
>
(
state
.
runs
[
0
].
iterations
);
static_cast
<
double
>
(
state
.
runs
[
0
].
iterations
);
#ifdef DEBUG
VLOG
(
1
)
<<
"Per-iteration overhead for doing nothing: "
<<
overhead
<<
"
\n
"
;
std
::
cout
<<
"Per-iteration overhead for doing nothing: "
<<
overhead
<<
"
\n
"
;
#endif
}
}
void
Benchmark
::
RunInstance
(
const
Instance
&
b
,
const
BenchmarkReporter
*
br
)
{
void
Benchmark
::
RunInstance
(
const
Instance
&
b
,
const
BenchmarkReporter
*
br
)
{
...
@@ -1091,20 +1088,16 @@ bool State::StartRunning() {
...
@@ -1091,20 +1088,16 @@ bool State::StartRunning() {
void
State
::
NewInterval
()
{
void
State
::
NewInterval
()
{
stop_time_micros_
=
clock_
->
NowMicros
()
+
interval_micros_
;
stop_time_micros_
=
clock_
->
NowMicros
()
+
interval_micros_
;
if
(
!
is_continuation_
)
{
if
(
!
is_continuation_
)
{
#ifdef DEBUG
VLOG
(
1
)
<<
"Starting new interval; stopping in "
<<
interval_micros_
std
::
cout
<<
"Starting new interval; stopping in "
<<
interval_micros_
<<
"
\n
"
;
<<
"
\n
"
;
#endif
iterations_
=
0
;
iterations_
=
0
;
pause_cpu_time_
=
0
;
pause_cpu_time_
=
0
;
pause_real_time_
=
0
;
pause_real_time_
=
0
;
start_cpu_
=
MyCPUUsage
()
+
ChildrenCPUUsage
();
start_cpu_
=
MyCPUUsage
()
+
ChildrenCPUUsage
();
start_time_
=
walltime
::
Now
();
start_time_
=
walltime
::
Now
();
}
else
{
}
else
{
#ifdef DEBUG
VLOG
(
1
)
<<
"Continuing interval; stopping in "
<<
interval_micros_
std
::
cout
<<
"Continuing interval; stopping in "
<<
interval_micros_
<<
"
\n
"
;
<<
"
\n
"
;
#endif
}
}
}
}
...
@@ -1114,10 +1107,8 @@ bool State::FinishInterval() {
...
@@ -1114,10 +1107,8 @@ bool State::FinishInterval() {
FLAGS_benchmark_iterations
/
FLAGS_benchmark_repetitions
)
||
FLAGS_benchmark_iterations
/
FLAGS_benchmark_repetitions
)
||
iterations_
<
1
)
{
iterations_
<
1
)
{
interval_micros_
*=
2
;
interval_micros_
*=
2
;
#ifdef DEBUG
VLOG
(
1
)
<<
"Not enough iterations in interval; "
std
::
cout
<<
"Not enough iterations in interval; "
<<
"Trying again for "
<<
interval_micros_
<<
" useconds.
\n
"
;
<<
"Trying again for "
<<
interval_micros_
<<
" useconds.
\n
"
;
#endif
is_continuation_
=
false
;
is_continuation_
=
false
;
NewInterval
();
NewInterval
();
return
true
;
return
true
;
...
@@ -1287,8 +1278,11 @@ void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter /*= nullptr*/) {
...
@@ -1287,8 +1278,11 @@ void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter /*= nullptr*/) {
}
}
void
Initialize
(
int
*
argc
,
const
char
**
argv
)
{
void
Initialize
(
int
*
argc
,
const
char
**
argv
)
{
walltime
::
Initialize
();
internal
::
ParseCommandLineFlags
(
argc
,
argv
);
internal
::
ParseCommandLineFlags
(
argc
,
argv
);
internal
::
SetLogLevel
(
FLAGS_v
);
// Ensure walltime is initialized by a single thread by forcing the
// initialization.
walltime
::
Now
();
internal
::
Benchmark
::
MeasureOverhead
();
internal
::
Benchmark
::
MeasureOverhead
();
}
}
...
...
src/check.h
View file @
4b3bbe34
#ifndef CHECK_H_
#ifndef CHECK_H_
#define CHECK_H_
#define CHECK_H_
#include <cassert>
#include <cstdlib>
#include <ostream>
#include "internal_macros.h"
#include "log.h"
namespace
benchmark
{
namespace
internal
{
// CheckHandler is the class constructed by failing CHECK macros. CheckHandler
// will log information about the failures and abort when it is destructed.
class
CheckHandler
{
public
:
CheckHandler
(
const
char
*
check
,
const
char
*
file
,
const
char
*
func
,
int
line
)
:
log_
(
GetErrorLogInstance
())
{
log_
<<
file
<<
":"
<<
line
<<
": "
<<
func
<<
": Check `"
<<
check
<<
"' failed. "
;
}
std
::
ostream
&
GetLog
()
{
return
log_
;
}
BENCHMARK_NORETURN
~
CheckHandler
()
{
log_
<<
std
::
endl
;
std
::
abort
();
}
private
:
std
::
ostream
&
log_
;
};
}
// end namespace internal
}
// end namespace benchmark
// The CHECK macro returns a std::ostream object that can have extra information
// written to it.
#ifndef NDEBUG
# define CHECK(b) (b ? ::benchmark::internal::GetNullLogInstance() \
: ::benchmark::internal::CheckHandler( \
#b, __FILE__, __func__, __LINE__).GetLog())
#else
# define CHECK(b) ::benchmark::internal::GetNullLogInstance()
#endif
#define CHECK(b) \
do { \
if (!(b)) assert(false); \
} while (0)
#define CHECK_EQ(a, b) CHECK((a) == (b))
#define CHECK_EQ(a, b) CHECK((a) == (b))
#define CHECK_NE(a, b) CHECK((a) != (b))
#define CHECK_NE(a, b) CHECK((a) != (b))
#define CHECK_GE(a, b) CHECK((a) >= (b))
#define CHECK_GE(a, b) CHECK((a) >= (b))
...
...
src/log.cc
0 → 100644
View file @
4b3bbe34
#include "log.h"
#include <iostream>
namespace
benchmark
{
namespace
internal
{
int
&
LoggingLevelImp
()
{
static
int
level
=
0
;
return
level
;
}
void
SetLogLevel
(
int
value
)
{
LoggingLevelImp
()
=
value
;
}
int
GetLogLevel
()
{
return
LoggingLevelImp
();
}
class
NullLogBuffer
:
public
std
::
streambuf
{
public
:
int
overflow
(
int
c
)
{
return
c
;
}
};
std
::
ostream
&
GetNullLogInstance
()
{
static
NullLogBuffer
log_buff
;
static
std
::
ostream
null_log
(
&
log_buff
);
return
null_log
;
}
std
::
ostream
&
GetErrorLogInstance
()
{
return
std
::
clog
;
}
}
// end namespace internal
}
// end namespace benchmark
\ No newline at end of file
src/log.h
0 → 100644
View file @
4b3bbe34
#ifndef BENCHMARK_LOG_H_
#define BENCHMARK_LOG_H_
#include <ostream>
namespace
benchmark
{
namespace
internal
{
int
GetLogLevel
();
void
SetLogLevel
(
int
level
);
std
::
ostream
&
GetNullLogInstance
();
std
::
ostream
&
GetErrorLogInstance
();
inline
std
::
ostream
&
GetLogInstanceForLevel
(
int
level
)
{
if
(
level
<=
GetLogLevel
())
{
return
GetErrorLogInstance
();
}
return
GetNullLogInstance
();
}
}
// end namespace internal
}
// end namespace benchmark
#define VLOG(x) (::benchmark::internal::GetLogInstanceForLevel(x) \
<< "-- LOG(" << x << "): ")
#endif
\ No newline at end of file
src/walltime.cc
View file @
4b3bbe34
// Copyright 201
4
Google Inc. All rights reserved.
// Copyright 201
5
Google Inc. All rights reserved.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// you may not use this file except in compliance with the License.
...
@@ -14,14 +14,16 @@
...
@@ -14,14 +14,16 @@
#include "walltime.h"
#include "walltime.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <sys/time.h>
#include <time.h>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <atomic>
#include <atomic>
#include <limits>
#include <limits>
#include <type_traits>
#include "check.h"
#include "check.h"
#include "cycleclock.h"
#include "cycleclock.h"
...
@@ -30,41 +32,6 @@
...
@@ -30,41 +32,6 @@
namespace
benchmark
{
namespace
benchmark
{
namespace
walltime
{
namespace
walltime
{
namespace
{
namespace
{
const
double
kMaxErrorInterval
=
100e-6
;
std
::
atomic
<
bool
>
initialized
(
false
);
WallTime
base_walltime
=
0.0
;
int64_t
base_cycletime
=
0
;
int64_t
cycles_per_second
;
double
seconds_per_cycle
;
uint32_t
last_adjust_time
=
0
;
std
::
atomic
<
int32_t
>
drift_adjust
(
0
);
int64_t
max_interval_cycles
=
0
;
// Helper routines to load/store a float from an AtomicWord. Required because
// g++ < 4.7 doesn't support std::atomic<float> correctly. I cannot wait to get
// rid of this horror show.
inline
void
SetDrift
(
float
f
)
{
int32_t
w
;
memcpy
(
&
w
,
&
f
,
sizeof
(
f
));
std
::
atomic_store
(
&
drift_adjust
,
w
);
}
inline
float
GetDrift
()
{
float
f
;
int32_t
w
=
std
::
atomic_load
(
&
drift_adjust
);
memcpy
(
&
f
,
&
w
,
sizeof
(
f
));
return
f
;
}
static_assert
(
sizeof
(
float
)
<=
sizeof
(
int32_t
),
"type sizes don't allow the drift_adjust hack"
);
WallTime
Slow
()
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
return
tv
.
tv_sec
+
tv
.
tv_usec
*
1e-6
;
}
bool
SplitTimezone
(
WallTime
value
,
bool
local
,
struct
tm
*
t
,
bool
SplitTimezone
(
WallTime
value
,
bool
local
,
struct
tm
*
t
,
double
*
subsecond
)
{
double
*
subsecond
)
{
...
@@ -81,58 +48,127 @@ bool SplitTimezone(WallTime value, bool local, struct tm* t,
...
@@ -81,58 +48,127 @@ bool SplitTimezone(WallTime value, bool local, struct tm* t,
gmtime_r
(
&
whole_time
,
t
);
gmtime_r
(
&
whole_time
,
t
);
return
true
;
return
true
;
}
}
}
// end namespace
// This routine should be invoked to initialize walltime.
// It is not intended for general purpose use.
void
Initialize
()
{
CHECK
(
!
std
::
atomic_load
(
&
initialized
));
cycles_per_second
=
static_cast
<
int64_t
>
(
CyclesPerSecond
());
CHECK
(
cycles_per_second
!=
0
);
seconds_per_cycle
=
1.0
/
cycles_per_second
;
max_interval_cycles
=
static_cast
<
int64_t
>
(
cycles_per_second
*
kMaxErrorInterval
);
do
{
base_cycletime
=
cycleclock
::
Now
();
base_walltime
=
Slow
();
}
while
(
cycleclock
::
Now
()
-
base_cycletime
>
max_interval_cycles
);
// We are now sure that "base_walltime" and "base_cycletime" were produced
// within kMaxErrorInterval of one another.
SetDrift
(
0.0
);
}
// end anonymous namespace
last_adjust_time
=
static_cast
<
uint32_t
>
(
uint64_t
(
base_cycletime
)
>>
32
);
std
::
atomic_store
(
&
initialized
,
true
);
}
namespace
{
class
WallTimeImp
{
public
:
WallTime
Now
();
static
WallTimeImp
&
GetWallTimeImp
()
{
static
WallTimeImp
imp
;
#if __cplusplus >= 201103L
static_assert
(
std
::
is_trivially_destructible
<
WallTimeImp
>::
value
,
"WallTimeImp must be trivially destructible to prevent "
"issues with static destruction"
);
#endif
return
imp
;
}
private
:
WallTimeImp
();
// Helper routines to load/store a float from an AtomicWord. Required because
// g++ < 4.7 doesn't support std::atomic<float> correctly. I cannot wait to
// get rid of this horror show.
void
SetDrift
(
float
f
)
{
int32_t
w
;
memcpy
(
&
w
,
&
f
,
sizeof
(
f
));
std
::
atomic_store
(
&
drift_adjust_
,
w
);
}
float
GetDrift
()
const
{
float
f
;
int32_t
w
=
std
::
atomic_load
(
&
drift_adjust_
);
memcpy
(
&
f
,
&
w
,
sizeof
(
f
));
return
f
;
}
WallTime
Slow
()
const
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
return
tv
.
tv_sec
+
tv
.
tv_usec
*
1e-6
;
}
private
:
static_assert
(
sizeof
(
float
)
<=
sizeof
(
int32_t
),
"type sizes don't allow the drift_adjust hack"
);
static
constexpr
double
kMaxErrorInterval
=
100e-6
;
WallTime
Now
()
{
WallTime
base_walltime_
;
if
(
!
std
::
atomic_load
(
&
initialized
))
return
Slow
();
int64_t
base_cycletime_
;
int64_t
cycles_per_second_
;
double
seconds_per_cycle_
;
uint32_t
last_adjust_time_
;
std
::
atomic
<
int32_t
>
drift_adjust_
;
int64_t
max_interval_cycles_
;
BENCHMARK_DISALLOW_COPY_AND_ASSIGN
(
WallTimeImp
);
};
WallTime
WallTimeImp
::
Now
()
{
WallTime
now
=
0.0
;
WallTime
now
=
0.0
;
WallTime
result
=
0.0
;
WallTime
result
=
0.0
;
int64_t
ct
=
0
;
int64_t
ct
=
0
;
uint32_t
top_bits
=
0
;
uint32_t
top_bits
=
0
;
do
{
do
{
ct
=
cycleclock
::
Now
();
ct
=
cycleclock
::
Now
();
int64_t
cycle_delta
=
ct
-
base_cycletime
;
int64_t
cycle_delta
=
ct
-
base_cycletime
_
;
result
=
base_walltime
+
cycle_delta
*
seconds_per_cycle
;
result
=
base_walltime
_
+
cycle_delta
*
seconds_per_cycle_
;
top_bits
=
static_cast
<
uint32_t
>
(
uint64_t
(
ct
)
>>
32
);
top_bits
=
static_cast
<
uint32_t
>
(
uint64_t
(
ct
)
>>
32
);
// Recompute drift no more often than every 2^32 cycles.
// Recompute drift no more often than every 2^32 cycles.
// I.e., @2GHz, ~ every two seconds
// I.e., @2GHz, ~ every two seconds
if
(
top_bits
==
last_adjust_time
)
{
// don't need to recompute drift
if
(
top_bits
==
last_adjust_time
_
)
{
// don't need to recompute drift
return
result
+
GetDrift
();
return
result
+
GetDrift
();
}
}
now
=
Slow
();
now
=
Slow
();
}
while
(
cycleclock
::
Now
()
-
ct
>
max_interval_cycles
);
}
while
(
cycleclock
::
Now
()
-
ct
>
max_interval_cycles
_
);
// We are now sure that "now" and "result" were produced within
// We are now sure that "now" and "result" were produced within
// kMaxErrorInterval of one another.
// kMaxErrorInterval of one another.
SetDrift
(
now
-
result
);
SetDrift
(
now
-
result
);
last_adjust_time
=
top_bits
;
last_adjust_time
_
=
top_bits
;
return
now
;
return
now
;
}
}
WallTimeImp
::
WallTimeImp
()
:
base_walltime_
(
0.0
),
base_cycletime_
(
0
),
cycles_per_second_
(
0
),
seconds_per_cycle_
(
0.0
),
last_adjust_time_
(
0
),
drift_adjust_
(
0
),
max_interval_cycles_
(
0
)
{
cycles_per_second_
=
static_cast
<
int64_t
>
(
CyclesPerSecond
());
CHECK
(
cycles_per_second_
!=
0
);
seconds_per_cycle_
=
1.0
/
cycles_per_second_
;
max_interval_cycles_
=
static_cast
<
int64_t
>
(
cycles_per_second_
*
kMaxErrorInterval
);
do
{
base_cycletime_
=
cycleclock
::
Now
();
base_walltime_
=
Slow
();
}
while
(
cycleclock
::
Now
()
-
base_cycletime_
>
max_interval_cycles_
);
// We are now sure that "base_walltime" and "base_cycletime" were produced
// within kMaxErrorInterval of one another.
SetDrift
(
0.0
);
last_adjust_time_
=
static_cast
<
uint32_t
>
(
uint64_t
(
base_cycletime_
)
>>
32
);
}
}
// end anonymous namespace
WallTime
Now
()
{
static
WallTimeImp
&
imp
=
WallTimeImp
::
GetWallTimeImp
();
return
imp
.
Now
();
}
std
::
string
Print
(
WallTime
time
,
const
char
*
format
,
bool
local
,
std
::
string
Print
(
WallTime
time
,
const
char
*
format
,
bool
local
,
int
*
remainder_us
)
{
int
*
remainder_us
)
{
char
storage
[
32
];
char
storage
[
32
];
...
@@ -150,5 +186,6 @@ std::string Print(WallTime time, const char* format, bool local,
...
@@ -150,5 +186,6 @@ std::string Print(WallTime time, const char* format, bool local,
}
}
return
std
::
string
(
storage
);
return
std
::
string
(
storage
);
}
}
}
// end namespace walltime
}
// end namespace walltime
}
// end namespace benchmark
}
// end namespace benchmark
src/walltime.h
View file @
4b3bbe34
...
@@ -7,7 +7,6 @@ namespace benchmark {
...
@@ -7,7 +7,6 @@ namespace benchmark {
typedef
double
WallTime
;
typedef
double
WallTime
;
namespace
walltime
{
namespace
walltime
{
void
Initialize
();
WallTime
Now
();
WallTime
Now
();
// GIVEN: walltime, generic format string (as understood by strftime),
// GIVEN: walltime, generic format string (as understood by strftime),
...
...
test/CMakeLists.txt
View file @
4b3bbe34
...
@@ -32,7 +32,7 @@ endmacro(add_gtest_test)
...
@@ -32,7 +32,7 @@ endmacro(add_gtest_test)
# Demonstration executable
# Demonstration executable
compile_benchmark_test
(
benchmark_test
)
compile_benchmark_test
(
benchmark_test
)
add_test
(
benchmark benchmark_test --benchmark_min_time=0.1 5
0
)
add_test
(
benchmark benchmark_test --benchmark_min_time=0.1 5
1
)
add_test
(
benchmark_filter_simple benchmark_test --benchmark_filter=Calculate 16
)
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_suffix benchmark_test --benchmark_filter=Calculate* 16
)
add_test
(
benchmark_filter_regex_wildcard benchmark_test --benchmark_filter=.*Calculate.* 16
)
add_test
(
benchmark_filter_regex_wildcard benchmark_test --benchmark_filter=.*Calculate.* 16
)
...
...
test/benchmark_test.cc
View file @
4b3bbe34
...
@@ -24,11 +24,9 @@
...
@@ -24,11 +24,9 @@
namespace
{
namespace
{
#ifdef DEBUG
int
BENCHMARK_NOINLINE
Factorial
(
uint32_t
n
)
{
int
BENCHMARK_NOINLINE
Factorial
(
uint32_t
n
)
{
return
(
n
==
1
)
?
1
:
n
*
Factorial
(
n
-
1
);
return
(
n
==
1
)
?
1
:
n
*
Factorial
(
n
-
1
);
}
}
#endif
double
CalculatePi
(
int
depth
)
{
double
CalculatePi
(
int
depth
)
{
double
pi
=
0.0
;
double
pi
=
0.0
;
...
@@ -52,7 +50,6 @@ std::vector<int>* test_vector = nullptr;
...
@@ -52,7 +50,6 @@ std::vector<int>* test_vector = nullptr;
}
// end namespace
}
// end namespace
#ifdef DEBUG
static
void
BM_Factorial
(
benchmark
::
State
&
state
)
{
static
void
BM_Factorial
(
benchmark
::
State
&
state
)
{
int
fac_42
=
0
;
int
fac_42
=
0
;
while
(
state
.
KeepRunning
())
while
(
state
.
KeepRunning
())
...
@@ -61,7 +58,6 @@ static void BM_Factorial(benchmark::State& state) {
...
@@ -61,7 +58,6 @@ static void BM_Factorial(benchmark::State& state) {
EXPECT_NE
(
fac_42
,
std
::
numeric_limits
<
int
>::
max
());
EXPECT_NE
(
fac_42
,
std
::
numeric_limits
<
int
>::
max
());
}
}
BENCHMARK
(
BM_Factorial
);
BENCHMARK
(
BM_Factorial
);
#endif
static
void
BM_CalculatePiRange
(
benchmark
::
State
&
state
)
{
static
void
BM_CalculatePiRange
(
benchmark
::
State
&
state
)
{
double
pi
=
0.0
;
double
pi
=
0.0
;
...
@@ -179,9 +175,7 @@ class TestReporter : public benchmark::internal::ConsoleReporter {
...
@@ -179,9 +175,7 @@ class TestReporter : public benchmark::internal::ConsoleReporter {
int
main
(
int
argc
,
const
char
*
argv
[])
{
int
main
(
int
argc
,
const
char
*
argv
[])
{
benchmark
::
Initialize
(
&
argc
,
argv
);
benchmark
::
Initialize
(
&
argc
,
argv
);
#ifdef DEBUG
assert
(
Factorial
(
8
)
==
40320
);
assert
(
Factorial
(
8
)
==
40320
);
#endif
assert
(
CalculatePi
(
1
)
==
0.0
);
assert
(
CalculatePi
(
1
)
==
0.0
);
TestReporter
test_reporter
;
TestReporter
test_reporter
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment