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
4ce184d8
Commit
4ce184d8
authored
Jan 09, 2014
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code reformat
parent
80093519
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
206 additions
and
200 deletions
+206
-200
benchmark.h
include/benchmark/benchmark.h
+30
-31
macros.h
include/benchmark/macros.h
+7
-4
benchmark.cc
src/benchmark.cc
+0
-0
colorprint.cc
src/colorprint.cc
+32
-18
commandlineflags.cc
src/commandlineflags.cc
+11
-15
commandlineflags.h
src/commandlineflags.h
+1
-1
cycleclock.h
src/cycleclock.h
+61
-61
mutex_lock.h
src/mutex_lock.h
+1
-3
sleep.cc
src/sleep.cc
+2
-4
stat.h
src/stat.h
+0
-0
sysinfo.cc
src/sysinfo.cc
+54
-55
walltime.cc
src/walltime.cc
+7
-8
No files found.
include/benchmark/benchmark.h
View file @
4ce184d8
...
@@ -194,7 +194,7 @@ class State {
...
@@ -194,7 +194,7 @@ class State {
//
//
// REQUIRES: a benchmark has exited its KeepRunning loop.
// REQUIRES: a benchmark has exited its KeepRunning loop.
void
SetBytesProcessed
(
int64_t
bytes
);
void
SetBytesProcessed
(
int64_t
bytes
);
// If this routine is called with items > 0, then an items/s
// If this routine is called with items > 0, then an items/s
// label is printed on the benchmark report line for the currently
// label is printed on the benchmark report line for the currently
// executing benchmark. It is typically called at the end of a processing
// executing benchmark. It is typically called at the end of a processing
...
@@ -243,11 +243,11 @@ class State {
...
@@ -243,11 +243,11 @@ class State {
void
Wait
();
void
Wait
();
enum
EState
{
enum
EState
{
STATE_INITIAL
,
// KeepRunning hasn't been called
STATE_INITIAL
,
// KeepRunning hasn't been called
STATE_STARTING
,
// KeepRunning called, waiting for other threads
STATE_STARTING
,
// KeepRunning called, waiting for other threads
STATE_RUNNING
,
// Running and being timed
STATE_RUNNING
,
// Running and being timed
STATE_STOPPING
,
// Not being timed but waiting for other threads
STATE_STOPPING
,
// Not being timed but waiting for other threads
STATE_STOPPED
,
// Stopped
STATE_STOPPED
,
// Stopped
};
};
EState
state_
;
EState
state_
;
...
@@ -414,8 +414,8 @@ class Benchmark {
...
@@ -414,8 +414,8 @@ class Benchmark {
static
void
RunInstance
(
const
Instance
&
b
,
BenchmarkReporter
*
br
);
static
void
RunInstance
(
const
Instance
&
b
,
BenchmarkReporter
*
br
);
friend
class
::
benchmark
::
State
;
friend
class
::
benchmark
::
State
;
friend
struct
::
benchmark
::
internal
::
Benchmark
::
Instance
;
friend
struct
::
benchmark
::
internal
::
Benchmark
::
Instance
;
friend
void
::
benchmark
::
internal
::
RunMatchingBenchmarks
(
friend
void
::
benchmark
::
internal
::
RunMatchingBenchmarks
(
const
std
::
string
&
,
const
std
::
string
&
,
BenchmarkReporter
*
);
BenchmarkReporter
*
);
DISALLOW_COPY_AND_ASSIGN
(
Benchmark
);
DISALLOW_COPY_AND_ASSIGN
(
Benchmark
);
};
};
...
@@ -425,7 +425,7 @@ class Benchmark {
...
@@ -425,7 +425,7 @@ class Benchmark {
struct
BenchmarkContextData
{
struct
BenchmarkContextData
{
int
num_cpus
;
int
num_cpus
;
double
mhz_per_cpu
;
double
mhz_per_cpu
;
//std::string cpu_info;
//
std::string cpu_info;
bool
cpu_scaling_enabled
;
bool
cpu_scaling_enabled
;
// The number of chars in the longest benchmark name.
// The number of chars in the longest benchmark name.
...
@@ -433,14 +433,14 @@ struct BenchmarkContextData {
...
@@ -433,14 +433,14 @@ struct BenchmarkContextData {
};
};
struct
BenchmarkRunData
{
struct
BenchmarkRunData
{
BenchmarkRunData
()
:
BenchmarkRunData
()
thread_index
(
-
1
),
:
thread_index
(
-
1
),
iterations
(
1
),
iterations
(
1
),
real_accumulated_time
(
0
),
real_accumulated_time
(
0
),
cpu_accumulated_time
(
0
),
cpu_accumulated_time
(
0
),
bytes_per_second
(
0
),
bytes_per_second
(
0
),
items_per_second
(
0
),
items_per_second
(
0
),
max_heapbytes_used
(
0
)
{}
max_heapbytes_used
(
0
)
{}
std
::
string
benchmark_name
;
std
::
string
benchmark_name
;
std
::
string
report_label
;
std
::
string
report_label
;
...
@@ -481,15 +481,13 @@ class BenchmarkReporter {
...
@@ -481,15 +481,13 @@ class BenchmarkReporter {
virtual
~
BenchmarkReporter
();
virtual
~
BenchmarkReporter
();
};
};
// ------------------------------------------------------
// ------------------------------------------------------
// Internal implementation details follow; please ignore
// Internal implementation details follow; please ignore
// Given a collection of reports, computes their mean and stddev.
// Given a collection of reports, computes their mean and stddev.
// REQUIRES: all runs in "reports" must be from the same benchmark.
// REQUIRES: all runs in "reports" must be from the same benchmark.
void
ComputeStats
(
const
std
::
vector
<
BenchmarkRunData
>&
reports
,
void
ComputeStats
(
const
std
::
vector
<
BenchmarkRunData
>&
reports
,
BenchmarkRunData
*
mean_data
,
BenchmarkRunData
*
mean_data
,
BenchmarkRunData
*
stddev_data
);
BenchmarkRunData
*
stddev_data
);
// Simple reporter that outputs benchmark data to the console. This is the
// Simple reporter that outputs benchmark data to the console. This is the
// default reporter used by RunSpecifiedBenchmarks().
// default reporter used by RunSpecifiedBenchmarks().
...
@@ -497,6 +495,7 @@ class ConsoleReporter : public BenchmarkReporter {
...
@@ -497,6 +495,7 @@ class ConsoleReporter : public BenchmarkReporter {
public
:
public
:
virtual
bool
ReportContext
(
const
BenchmarkContextData
&
context
);
virtual
bool
ReportContext
(
const
BenchmarkContextData
&
context
);
virtual
void
ReportRuns
(
const
std
::
vector
<
BenchmarkRunData
>&
reports
);
virtual
void
ReportRuns
(
const
std
::
vector
<
BenchmarkRunData
>&
reports
);
private
:
private
:
std
::
string
PrintMemoryUsage
(
double
bytes
);
std
::
string
PrintMemoryUsage
(
double
bytes
);
virtual
void
PrintRunData
(
const
BenchmarkRunData
&
report
);
virtual
void
PrintRunData
(
const
BenchmarkRunData
&
report
);
...
@@ -513,11 +512,11 @@ void Initialize(int* argc, const char** argv);
...
@@ -513,11 +512,11 @@ void Initialize(int* argc, const char** argv);
// Helpers for generating unique variable names
// Helpers for generating unique variable names
#define BENCHMARK_CONCAT(a, b, c) BENCHMARK_CONCAT2(a, b, c)
#define BENCHMARK_CONCAT(a, b, c) BENCHMARK_CONCAT2(a, b, c)
#define BENCHMARK_CONCAT2(a, b, c) a
## b ##
c
#define BENCHMARK_CONCAT2(a, b, c) a
##b##
c
#define BENCHMARK(n)
\
#define BENCHMARK(n) \
static ::benchmark::internal::Benchmark*
\
static ::benchmark::internal::Benchmark* BENCHMARK_CONCAT(
\
BENCHMARK_CONCAT(__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
(new ::benchmark::internal::Benchmark(#n, n))
(new ::benchmark::internal::Benchmark(#n, n))
// Old-style macros
// Old-style macros
...
@@ -525,7 +524,7 @@ void Initialize(int* argc, const char** argv);
...
@@ -525,7 +524,7 @@ void Initialize(int* argc, const char** argv);
#define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->ArgPair((a1), (a2))
#define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->ArgPair((a1), (a2))
#define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
#define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
#define BENCHMARK_RANGE2(n, l1, h1, l2, h2) \
#define BENCHMARK_RANGE2(n, l1, h1, l2, h2) \
BENCHMARK(n)->RangePair((l1), (h1), (l2), (h2))
BENCHMARK(n)->RangePair((l1), (h1), (l2), (h2))
// This will register a benchmark for a templatized function. For example:
// This will register a benchmark for a templatized function. For example:
//
//
...
@@ -535,14 +534,14 @@ void Initialize(int* argc, const char** argv);
...
@@ -535,14 +534,14 @@ void Initialize(int* argc, const char** argv);
// BENCHMARK_TEMPLATE(BM_Foo, 1);
// BENCHMARK_TEMPLATE(BM_Foo, 1);
//
//
// will register BM_Foo<1> as a benchmark.
// will register BM_Foo<1> as a benchmark.
#define BENCHMARK_TEMPLATE(n, a)
\
#define BENCHMARK_TEMPLATE(n, a) \
static ::benchmark::internal::Benchmark*
\
static ::benchmark::internal::Benchmark* BENCHMARK_CONCAT(
\
BENCHMARK_CONCAT(__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
(new ::benchmark::internal::Benchmark(#n "<" #a ">", n<a>))
(new ::benchmark::internal::Benchmark(#n "<" #a ">", n<a>))
#define BENCHMARK_TEMPLATE2(n, a, b)
\
#define BENCHMARK_TEMPLATE2(n, a, b) \
static ::benchmark::internal::Benchmark*
\
static ::benchmark::internal::Benchmark*
BENCHMARK_CONCAT(
\
BENCHMARK_CONCAT(__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
(new ::benchmark::internal::Benchmark(#n "<" #a "," #b ">", n<a, b>))
(new ::benchmark::internal::Benchmark(#n "<" #a "," #b ">", n<a, b>))
#endif // BENCHMARK_BENCHMARK_H_
#endif // BENCHMARK_BENCHMARK_H_
...
...
include/benchmark/macros.h
View file @
4ce184d8
...
@@ -34,7 +34,10 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
...
@@ -34,7 +34,10 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
#define CHECK(b) do { if (!(b)) assert(false); } while(0)
#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))
...
@@ -45,14 +48,14 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
...
@@ -45,14 +48,14 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
//
//
// Prevent the compiler from complaining about or optimizing away variables
// Prevent the compiler from complaining about or optimizing away variables
// that appear unused.
// that appear unused.
#define ATTRIBUTE_UNUSED __attribute__
((unused))
#define ATTRIBUTE_UNUSED __attribute__((unused))
//
//
// For functions we want to force inline or not inline.
// For functions we want to force inline or not inline.
// Introduced in gcc 3.1.
// Introduced in gcc 3.1.
#define ATTRIBUTE_ALWAYS_INLINE
__attribute__
((always_inline))
#define ATTRIBUTE_ALWAYS_INLINE
__attribute__
((always_inline))
#define HAVE_ATTRIBUTE_ALWAYS_INLINE 1
#define HAVE_ATTRIBUTE_ALWAYS_INLINE 1
#define ATTRIBUTE_NOINLINE __attribute__
((noinline))
#define ATTRIBUTE_NOINLINE __attribute__((noinline))
#define HAVE_ATTRIBUTE_NOINLINE 1
#define HAVE_ATTRIBUTE_NOINLINE 1
#endif // BENCHMARK_MACROS_H_
#endif // BENCHMARK_MACROS_H_
src/benchmark.cc
View file @
4ce184d8
This diff is collapsed.
Click to expand it.
src/colorprint.cc
View file @
4ce184d8
...
@@ -17,25 +17,40 @@ typedef const char* PlatformColorCode;
...
@@ -17,25 +17,40 @@ typedef const char* PlatformColorCode;
PlatformColorCode
GetPlatformColorCode
(
LogColor
color
)
{
PlatformColorCode
GetPlatformColorCode
(
LogColor
color
)
{
#ifdef OS_WINDOWS
#ifdef OS_WINDOWS
switch
(
color
)
{
switch
(
color
)
{
case
COLOR_RED
:
return
FOREGROUND_RED
;
case
COLOR_RED
:
case
COLOR_GREEN
:
return
FOREGROUND_GREEN
;
return
FOREGROUND_RED
;
case
COLOR_YELLOW
:
return
FOREGROUND_RED
|
FOREGROUND_GREEN
;
case
COLOR_GREEN
:
case
COLOR_BLUE
:
return
FOREGROUND_BLUE
;
return
FOREGROUND_GREEN
;
case
COLOR_MAGENTA
:
return
FOREGROUND_BLUE
|
FOREGROUND_RED
;
case
COLOR_YELLOW
:
case
COLOR_CYAN
:
return
FOREGROUND_BLUE
|
FOREGROUND_GREEN
;
return
FOREGROUND_RED
|
FOREGROUND_GREEN
;
case
COLOR_WHITE
:
// fall through to default
case
COLOR_BLUE
:
default:
return
0
;
return
FOREGROUND_BLUE
;
case
COLOR_MAGENTA
:
return
FOREGROUND_BLUE
|
FOREGROUND_RED
;
case
COLOR_CYAN
:
return
FOREGROUND_BLUE
|
FOREGROUND_GREEN
;
case
COLOR_WHITE
:
// fall through to default
default:
return
0
;
}
}
#else
#else
switch
(
color
)
{
switch
(
color
)
{
case
COLOR_RED
:
return
"1"
;
case
COLOR_RED
:
case
COLOR_GREEN
:
return
"2"
;
return
"1"
;
case
COLOR_YELLOW
:
return
"3"
;
case
COLOR_GREEN
:
case
COLOR_BLUE
:
return
"4"
;
return
"2"
;
case
COLOR_MAGENTA
:
return
"5"
;
case
COLOR_YELLOW
:
case
COLOR_CYAN
:
return
"6"
;
return
"3"
;
case
COLOR_WHITE
:
return
"7"
;
case
COLOR_BLUE
:
default:
return
NULL
;
return
"4"
;
case
COLOR_MAGENTA
:
return
"5"
;
case
COLOR_CYAN
:
return
"6"
;
case
COLOR_WHITE
:
return
"7"
;
default:
return
NULL
;
};
};
#endif
#endif
}
}
...
@@ -72,8 +87,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
...
@@ -72,8 +87,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
SetConsoleTextAttribute
(
stdout_handle
,
old_color_attrs
);
SetConsoleTextAttribute
(
stdout_handle
,
old_color_attrs
);
#else
#else
const
char
*
color_code
=
GetPlatformColorCode
(
color
);
const
char
*
color_code
=
GetPlatformColorCode
(
color
);
if
(
color_code
)
if
(
color_code
)
fprintf
(
stdout
,
"
\033
[0;3%sm"
,
color_code
);
fprintf
(
stdout
,
"
\033
[0;3%sm"
,
color_code
);
vprintf
(
fmt
,
args
);
vprintf
(
fmt
,
args
);
printf
(
"
\033
[m"
);
// Resets the terminal to default.
printf
(
"
\033
[m"
);
// Resets the terminal to default.
#endif
#endif
...
...
src/commandlineflags.cc
View file @
4ce184d8
...
@@ -29,7 +29,7 @@ bool ParseInt32(const std::string& src_text, const char* str, int32_t* value) {
...
@@ -29,7 +29,7 @@ bool ParseInt32(const std::string& src_text, const char* str, int32_t* value) {
// The parsed value overflows as a long. (strtol() returns
// The parsed value overflows as a long. (strtol() returns
// LONG_MAX or LONG_MIN when the input overflows.)
// LONG_MAX or LONG_MIN when the input overflows.)
result
!=
long_value
result
!=
long_value
// The parsed value overflows as an Int32.
// The parsed value overflows as an Int32.
)
{
)
{
std
::
cerr
<<
src_text
<<
" is expected to be a 32-bit integer, "
std
::
cerr
<<
src_text
<<
" is expected to be a 32-bit integer, "
<<
"but actually has value
\"
"
<<
str
<<
"
\"
, "
<<
"but actually has value
\"
"
<<
str
<<
"
\"
, "
...
@@ -60,7 +60,6 @@ bool ParseDouble(const std::string& src_text, const char* str, double* value) {
...
@@ -60,7 +60,6 @@ bool ParseDouble(const std::string& src_text, const char* str, double* value) {
return
true
;
return
true
;
}
}
inline
const
char
*
GetEnv
(
const
char
*
name
)
{
inline
const
char
*
GetEnv
(
const
char
*
name
)
{
#if GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS_MOBILE
// We are on Windows CE, which has no environment variables.
// We are on Windows CE, which has no environment variables.
...
@@ -95,8 +94,7 @@ static std::string FlagToEnvVar(const char* flag) {
...
@@ -95,8 +94,7 @@ static std::string FlagToEnvVar(const char* flag) {
bool
BoolFromEnv
(
const
char
*
flag
,
bool
default_value
)
{
bool
BoolFromEnv
(
const
char
*
flag
,
bool
default_value
)
{
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
const
string_value
=
GetEnv
(
env_var
.
c_str
());
const
char
*
const
string_value
=
GetEnv
(
env_var
.
c_str
());
return
string_value
==
NULL
?
return
string_value
==
NULL
?
default_value
:
strcmp
(
string_value
,
"0"
)
!=
0
;
default_value
:
strcmp
(
string_value
,
"0"
)
!=
0
;
}
}
// Reads and returns a 32-bit integer stored in the environment
// Reads and returns a 32-bit integer stored in the environment
...
@@ -111,8 +109,8 @@ int32_t Int32FromEnv(const char* flag, int32_t default_value) {
...
@@ -111,8 +109,8 @@ int32_t Int32FromEnv(const char* flag, int32_t default_value) {
}
}
int32_t
result
=
default_value
;
int32_t
result
=
default_value
;
if
(
!
ParseInt32
(
std
::
string
(
"Environment variable "
)
+
env_var
,
if
(
!
ParseInt32
(
std
::
string
(
"Environment variable "
)
+
env_var
,
string_value
,
string_value
,
&
result
))
{
&
result
))
{
std
::
cout
<<
"The default value "
<<
default_value
<<
" is used.
\n
"
;
std
::
cout
<<
"The default value "
<<
default_value
<<
" is used.
\n
"
;
return
default_value
;
return
default_value
;
}
}
...
@@ -133,13 +131,12 @@ const char* StringFromEnv(const char* flag, const char* default_value) {
...
@@ -133,13 +131,12 @@ const char* StringFromEnv(const char* flag, const char* default_value) {
// part can be omitted.
// part can be omitted.
//
//
// Returns the value of the flag, or NULL if the parsing failed.
// Returns the value of the flag, or NULL if the parsing failed.
const
char
*
ParseFlagValue
(
const
char
*
str
,
const
char
*
ParseFlagValue
(
const
char
*
str
,
const
char
*
flag
,
const
char
*
flag
,
bool
def_optional
)
{
bool
def_optional
)
{
// str and flag must not be NULL.
// str and flag must not be NULL.
if
(
str
==
NULL
||
flag
==
NULL
)
return
NULL
;
if
(
str
==
NULL
||
flag
==
NULL
)
return
NULL
;
// The flag must start with "--".
// The flag must start with "--".
const
std
::
string
flag_str
=
std
::
string
(
"--"
)
+
std
::
string
(
flag
);
const
std
::
string
flag_str
=
std
::
string
(
"--"
)
+
std
::
string
(
flag
);
const
size_t
flag_len
=
flag_str
.
length
();
const
size_t
flag_len
=
flag_str
.
length
();
if
(
strncmp
(
str
,
flag_str
.
c_str
(),
flag_len
)
!=
0
)
return
NULL
;
if
(
strncmp
(
str
,
flag_str
.
c_str
(),
flag_len
)
!=
0
)
return
NULL
;
...
@@ -148,8 +145,7 @@ const char* ParseFlagValue(const char* str,
...
@@ -148,8 +145,7 @@ const char* ParseFlagValue(const char* str,
const
char
*
flag_end
=
str
+
flag_len
;
const
char
*
flag_end
=
str
+
flag_len
;
// When def_optional is true, it's OK to not have a "=value" part.
// When def_optional is true, it's OK to not have a "=value" part.
if
(
def_optional
&&
(
flag_end
[
0
]
==
'\0'
))
if
(
def_optional
&&
(
flag_end
[
0
]
==
'\0'
))
return
flag_end
;
return
flag_end
;
// If def_optional is true and there are more characters after the
// If def_optional is true and there are more characters after the
// flag name, or if def_optional is false, there must be a '=' after
// flag name, or if def_optional is false, there must be a '=' after
...
@@ -180,8 +176,8 @@ bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) {
...
@@ -180,8 +176,8 @@ bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) {
if
(
value_str
==
NULL
)
return
false
;
if
(
value_str
==
NULL
)
return
false
;
// Sets *value to the value of the flag.
// Sets *value to the value of the flag.
return
ParseInt32
(
std
::
string
(
"The value of flag --"
)
+
flag
,
return
ParseInt32
(
std
::
string
(
"The value of flag --"
)
+
flag
,
value_str
,
value
_str
,
value
);
value
);
}
}
bool
ParseDoubleFlag
(
const
char
*
str
,
const
char
*
flag
,
double
*
value
)
{
bool
ParseDoubleFlag
(
const
char
*
str
,
const
char
*
flag
,
double
*
value
)
{
...
@@ -192,8 +188,8 @@ bool ParseDoubleFlag(const char* str, const char* flag, double* value) {
...
@@ -192,8 +188,8 @@ bool ParseDoubleFlag(const char* str, const char* flag, double* value) {
if
(
value_str
==
NULL
)
return
false
;
if
(
value_str
==
NULL
)
return
false
;
// Sets *value to the value of the flag.
// Sets *value to the value of the flag.
return
ParseDouble
(
std
::
string
(
"The value of flag --"
)
+
flag
,
return
ParseDouble
(
std
::
string
(
"The value of flag --"
)
+
flag
,
value_str
,
value
_str
,
value
);
value
);
}
}
bool
ParseStringFlag
(
const
char
*
str
,
const
char
*
flag
,
std
::
string
*
value
)
{
bool
ParseStringFlag
(
const
char
*
str
,
const
char
*
flag
,
std
::
string
*
value
)
{
...
...
src/commandlineflags.h
View file @
4ce184d8
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#define DEFINE_int64(name, default_val, doc) int64_t FLAG(name) = (default_val)
#define DEFINE_int64(name, default_val, doc) int64_t FLAG(name) = (default_val)
#define DEFINE_double(name, default_val, doc) double FLAG(name) = (default_val)
#define DEFINE_double(name, default_val, doc) double FLAG(name) = (default_val)
#define DEFINE_string(name, default_val, doc) \
#define DEFINE_string(name, default_val, doc) \
std::string FLAG(name) = (default_val)
std::string FLAG(name) = (default_val)
namespace
benchmark
{
namespace
benchmark
{
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
...
...
src/cycleclock.h
View file @
4ce184d8
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
#include <stdint.h>
#include <stdint.h>
#if defined(OS_MACOSX)
#if defined(OS_MACOSX)
#
include <mach/mach_time.h>
#include <mach/mach_time.h>
#endif
#endif
// For MSVC, we want to use '_asm rdtsc' when possible (since it works
// For MSVC, we want to use '_asm rdtsc' when possible (since it works
// with even ancient MSVC compilers), and when not possible the
// with even ancient MSVC compilers), and when not possible the
...
@@ -48,85 +48,85 @@ namespace benchmark {
...
@@ -48,85 +48,85 @@ namespace benchmark {
// with modifications by m3b. See also
// with modifications by m3b. See also
// https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h
// https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h
namespace
cycleclock
{
namespace
cycleclock
{
// This should return the number of cycles since power-on. Thread-safe.
// This should return the number of cycles since power-on. Thread-safe.
inline
ATTRIBUTE_ALWAYS_INLINE
int64_t
Now
()
{
inline
ATTRIBUTE_ALWAYS_INLINE
int64_t
Now
()
{
#if defined(OS_MACOSX)
#if defined(OS_MACOSX)
// this goes at the top because we need ALL Macs, regardless of
// this goes at the top because we need ALL Macs, regardless of
// architecture, to return the number of "mach time units" that
// architecture, to return the number of "mach time units" that
// have passed since startup. See sysinfo.cc where
// have passed since startup. See sysinfo.cc where
// InitializeSystemInfo() sets the supposed cpu clock frequency of
// InitializeSystemInfo() sets the supposed cpu clock frequency of
// macs to the number of mach time units per second, not actual
// macs to the number of mach time units per second, not actual
// CPU clock frequency (which can change in the face of CPU
// CPU clock frequency (which can change in the face of CPU
// frequency scaling). Also note that when the Mac sleeps, this
// frequency scaling). Also note that when the Mac sleeps, this
// counter pauses; it does not continue counting, nor does it
// counter pauses; it does not continue counting, nor does it
// reset to zero.
// reset to zero.
return
mach_absolute_time
();
return
mach_absolute_time
();
#elif defined(__i386__)
#elif defined(__i386__)
int64_t
ret
;
int64_t
ret
;
__asm__
volatile
(
"rdtsc"
:
"=A"
(
ret
)
);
__asm__
volatile
(
"rdtsc"
:
"=A"
(
ret
)
);
return
ret
;
return
ret
;
#elif defined(__x86_64__) || defined(__amd64__)
#elif defined(__x86_64__) || defined(__amd64__)
uint64_t
low
,
high
;
uint64_t
low
,
high
;
__asm__
volatile
(
"rdtsc"
:
"=a"
(
low
),
"=d"
(
high
));
__asm__
volatile
(
"rdtsc"
:
"=a"
(
low
),
"=d"
(
high
));
return
(
high
<<
32
)
|
low
;
return
(
high
<<
32
)
|
low
;
#elif defined(__powerpc__) || defined(__ppc__)
#elif defined(__powerpc__) || defined(__ppc__)
// This returns a time-base, which is not always precisely a cycle-count.
// This returns a time-base, which is not always precisely a cycle-count.
int64_t
tbl
,
tbu0
,
tbu1
;
int64_t
tbl
,
tbu0
,
tbu1
;
asm
(
"mftbu %0"
:
"=r"
(
tbu0
));
asm
(
"mftbu %0"
:
"=r"
(
tbu0
));
asm
(
"mftb %0"
:
"=r"
(
tbl
));
asm
(
"mftb %0"
:
"=r"
(
tbl
));
asm
(
"mftbu %0"
:
"=r"
(
tbu1
));
asm
(
"mftbu %0"
:
"=r"
(
tbu1
));
tbl
&=
-
static_cast
<
int64
>
(
tbu0
==
tbu1
);
tbl
&=
-
static_cast
<
int64
>
(
tbu0
==
tbu1
);
// high 32 bits in tbu1; low 32 bits in tbl (tbu0 is garbage)
// high 32 bits in tbu1; low 32 bits in tbl (tbu0 is garbage)
return
(
tbu1
<<
32
)
|
tbl
;
return
(
tbu1
<<
32
)
|
tbl
;
#elif defined(__sparc__)
#elif defined(__sparc__)
int64_t
tick
;
int64_t
tick
;
asm
(
".byte 0x83, 0x41, 0x00, 0x00"
);
asm
(
".byte 0x83, 0x41, 0x00, 0x00"
);
asm
(
"mov %%g1, %0"
:
"=r"
(
tick
));
asm
(
"mov %%g1, %0"
:
"=r"
(
tick
));
return
tick
;
return
tick
;
#elif defined(__ia64__)
#elif defined(__ia64__)
int64_t
itc
;
int64_t
itc
;
asm
(
"mov %0 = ar.itc"
:
"=r"
(
itc
));
asm
(
"mov %0 = ar.itc"
:
"=r"
(
itc
));
return
itc
;
return
itc
;
#elif defined(COMPILER_MSVC) && defined(_M_IX86)
#elif defined(COMPILER_MSVC) && defined(_M_IX86)
// Older MSVC compilers (like 7.x) don't seem to support the
// Older MSVC compilers (like 7.x) don't seem to support the
// __rdtsc intrinsic properly, so I prefer to use _asm instead
// __rdtsc intrinsic properly, so I prefer to use _asm instead
// when I know it will work. Otherwise, I'll use __rdtsc and hope
// when I know it will work. Otherwise, I'll use __rdtsc and hope
// the code is being compiled with a non-ancient compiler.
// the code is being compiled with a non-ancient compiler.
_asm
rdtsc
_asm
rdtsc
#elif defined(COMPILER_MSVC)
#elif defined(COMPILER_MSVC)
return
__rdtsc
();
return
__rdtsc
();
#elif defined(ARMV3)
#elif defined(ARMV3)
#if defined(ARMV6) // V6 is the earliest arch that has a standard cyclecount
#if defined(ARMV6) // V6 is the earliest arch that has a standard cyclecount
uint32_t
pmccntr
;
uint32_t
pmccntr
;
uint32_t
pmuseren
;
uint32_t
pmuseren
;
uint32_t
pmcntenset
;
uint32_t
pmcntenset
;
// Read the user mode perf monitor counter access permissions.
// Read the user mode perf monitor counter access permissions.
asm
(
"mrc p15, 0, %0, c9, c14, 0"
:
"=r"
(
pmuseren
));
asm
(
"mrc p15, 0, %0, c9, c14, 0"
:
"=r"
(
pmuseren
));
if
(
pmuseren
&
1
)
{
// Allows reading perfmon counters for user mode code.
if
(
pmuseren
&
1
)
{
// Allows reading perfmon counters for user mode code.
asm
(
"mrc p15, 0, %0, c9, c12, 1"
:
"=r"
(
pmcntenset
));
asm
(
"mrc p15, 0, %0, c9, c12, 1"
:
"=r"
(
pmcntenset
));
if
(
pmcntenset
&
0x80000000ul
)
{
// Is it counting?
if
(
pmcntenset
&
0x80000000ul
)
{
// Is it counting?
asm
(
"mrc p15, 0, %0, c9, c13, 0"
:
"=r"
(
pmccntr
));
asm
(
"mrc p15, 0, %0, c9, c13, 0"
:
"=r"
(
pmccntr
));
// The counter is set up to count every 64th cycle
// The counter is set up to count every 64th cycle
return
static_cast
<
int64
>
(
pmccntr
)
*
64
;
// Should optimize to << 6
return
static_cast
<
int64
>
(
pmccntr
)
*
64
;
// Should optimize to << 6
}
}
}
}
#endif
#endif
struct
timeval
tv
;
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
gettimeofday
(
&
tv
,
NULL
);
return
static_cast
<
int64_t
>
(
tv
.
tv_sec
)
*
1000000
+
tv
.
tv_usec
;
return
static_cast
<
int64_t
>
(
tv
.
tv_sec
)
*
1000000
+
tv
.
tv_usec
;
#elif defined(__mips__)
#elif defined(__mips__)
// mips apparently only allows rdtsc for superusers, so we fall
// mips apparently only allows rdtsc for superusers, so we fall
// back to gettimeofday. It's possible clock_gettime would be better.
// back to gettimeofday. It's possible clock_gettime would be better.
struct
timeval
tv
;
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
gettimeofday
(
&
tv
,
NULL
);
return
static_cast
<
int64_t
>
(
tv
.
tv_sec
)
*
1000000
+
tv
.
tv_usec
;
return
static_cast
<
int64_t
>
(
tv
.
tv_sec
)
*
1000000
+
tv
.
tv_usec
;
#else
#else
// The soft failover to a generic implementation is automatic only for ARM.
// The soft failover to a generic implementation is automatic only for ARM.
// For other platforms the developer is expected to make an attempt to create
// For other platforms the developer is expected to make an attempt to create
// a fast implementation and use generic version if nothing better is available.
// a fast implementation and use generic version if nothing better is available.
#error You need to define CycleTimer for your OS and CPU
#error You need to define CycleTimer for your OS and CPU
#endif
#endif
}
}
}
// end namespace cycleclock
}
// end namespace cycleclock
}
// end namespace benchmark
}
// end namespace benchmark
...
...
src/mutex_lock.h
View file @
4ce184d8
...
@@ -10,9 +10,7 @@ class mutex_lock {
...
@@ -10,9 +10,7 @@ class mutex_lock {
pthread_mutex_lock
(
mu_
);
pthread_mutex_lock
(
mu_
);
}
}
~
mutex_lock
()
{
~
mutex_lock
()
{
pthread_mutex_unlock
(
mu_
);
}
pthread_mutex_unlock
(
mu_
);
}
private
:
private
:
pthread_mutex_t
*
mu_
;
pthread_mutex_t
*
mu_
;
...
...
src/sleep.cc
View file @
4ce184d8
...
@@ -6,13 +6,11 @@
...
@@ -6,13 +6,11 @@
namespace
benchmark
{
namespace
benchmark
{
#ifdef OS_WINDOWS
#ifdef OS_WINDOWS
// Window's _sleep takes milliseconds argument.
// Window's _sleep takes milliseconds argument.
void
SleepForMilliseconds
(
int
milliseconds
)
{
void
SleepForMilliseconds
(
int
milliseconds
)
{
_sleep
(
milliseconds
);
}
_sleep
(
milliseconds
);
}
void
SleepForSeconds
(
double
seconds
)
{
void
SleepForSeconds
(
double
seconds
)
{
SleepForMilliseconds
(
static_cast
<
int
>
(
kNumMillisPerSecond
*
seconds
));
SleepForMilliseconds
(
static_cast
<
int
>
(
kNumMillisPerSecond
*
seconds
));
}
}
#else // OS_WINDOWS
#else
// OS_WINDOWS
void
SleepForMicroseconds
(
int64_t
microseconds
)
{
void
SleepForMicroseconds
(
int64_t
microseconds
)
{
struct
timespec
sleep_time
;
struct
timespec
sleep_time
;
sleep_time
.
tv_sec
=
microseconds
/
kNumMicrosPerSecond
;
sleep_time
.
tv_sec
=
microseconds
/
kNumMicrosPerSecond
;
...
...
src/stat.h
View file @
4ce184d8
This diff is collapsed.
Click to expand it.
src/sysinfo.cc
View file @
4ce184d8
This diff is collapsed.
Click to expand it.
src/walltime.cc
View file @
4ce184d8
...
@@ -75,8 +75,8 @@ void Initialize() {
...
@@ -75,8 +75,8 @@ void Initialize() {
cycles_per_second
=
static_cast
<
int64_t
>
(
CyclesPerSecond
());
cycles_per_second
=
static_cast
<
int64_t
>
(
CyclesPerSecond
());
CHECK
(
cycles_per_second
!=
0
);
CHECK
(
cycles_per_second
!=
0
);
seconds_per_cycle
=
1.0
/
cycles_per_second
;
seconds_per_cycle
=
1.0
/
cycles_per_second
;
max_interval_cycles
=
static_cast
<
int64_t
>
(
max_interval_cycles
=
cycles_per_second
*
kMaxErrorInterval
);
static_cast
<
int64_t
>
(
cycles_per_second
*
kMaxErrorInterval
);
do
{
do
{
base_cycletime
=
cycleclock
::
Now
();
base_cycletime
=
cycleclock
::
Now
();
base_walltime
=
Slow
();
base_walltime
=
Slow
();
...
@@ -90,8 +90,7 @@ void Initialize() {
...
@@ -90,8 +90,7 @@ void Initialize() {
}
}
WallTime
Now
()
{
WallTime
Now
()
{
if
(
!
std
::
atomic_load
(
&
initialized
))
if
(
!
std
::
atomic_load
(
&
initialized
))
return
Slow
();
return
Slow
();
WallTime
now
=
0.0
;
WallTime
now
=
0.0
;
WallTime
result
=
0.0
;
WallTime
result
=
0.0
;
...
@@ -105,7 +104,7 @@ WallTime Now() {
...
@@ -105,7 +104,7 @@ WallTime Now() {
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
();
}
}
...
@@ -119,8 +118,8 @@ WallTime Now() {
...
@@ -119,8 +118,8 @@ WallTime Now() {
return
now
;
return
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
];
struct
tm
split
;
struct
tm
split
;
double
subsecond
;
double
subsecond
;
...
@@ -130,7 +129,7 @@ std::string Print(WallTime time, const char *format, bool local,
...
@@ -130,7 +129,7 @@ std::string Print(WallTime time, const char *format, bool local,
if
(
remainder_us
!=
NULL
)
{
if
(
remainder_us
!=
NULL
)
{
*
remainder_us
=
static_cast
<
int
>
((
subsecond
*
1000000
)
+
0.5
);
*
remainder_us
=
static_cast
<
int
>
((
subsecond
*
1000000
)
+
0.5
);
if
(
*
remainder_us
>
999999
)
*
remainder_us
=
999999
;
if
(
*
remainder_us
>
999999
)
*
remainder_us
=
999999
;
if
(
*
remainder_us
<
0
)
*
remainder_us
=
0
;
if
(
*
remainder_us
<
0
)
*
remainder_us
=
0
;
}
}
strftime
(
storage
,
sizeof
(
storage
),
format
,
&
split
);
strftime
(
storage
,
sizeof
(
storage
),
format
,
&
split
);
}
}
...
...
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