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
e390e4eb
Commit
e390e4eb
authored
Dec 19, 2013
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding benchmark namespace and removing broken flags
parent
403f3544
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
41 additions
and
94 deletions
+41
-94
macros.h
include/benchmark/macros.h
+0
-63
benchmark.cc
src/benchmark.cc
+11
-10
colorprint.cc
src/colorprint.cc
+2
-1
colorprint.h
src/colorprint.h
+2
-0
commandlineflags.h
src/commandlineflags.h
+0
-1
cycleclock.h
src/cycleclock.h
+4
-2
mutex_lock.h
src/mutex_lock.h
+2
-0
port.h
src/port.h
+0
-8
sleep.cc
src/sleep.cc
+2
-2
sleep.h
src/sleep.h
+2
-0
stat.h
src/stat.h
+2
-0
sysinfo.cc
src/sysinfo.cc
+4
-3
sysinfo.h
src/sysinfo.h
+2
-0
walltime.cc
src/walltime.cc
+6
-4
walltime.h
src/walltime.h
+2
-0
No files found.
include/benchmark/macros.h
View file @
e390e4eb
...
...
@@ -34,69 +34,6 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
// The STATIC_ASSERT macro can be used to verify that a compile time
// expression is true. For example, you could use it to verify the
// size of a static array:
//
// STATIC_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
// content_type_names_incorrect_size);
//
// or to make sure a struct is smaller than a certain size:
//
// STATIC_ASSERT(sizeof(foo) < 128, foo_too_large);
//
// The second argument to the macro is the name of the variable. If
// the expression is false, most compilers will issue a warning/error
// containing the name of the variable.
template
<
bool
>
struct
StaticAssert
{
};
#define STATIC_ASSERT(expr, msg) \
typedef StaticAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
// Implementation details of STATIC_ASSERT:
//
// - STATIC_ASSERT works by defining an array type that has -1
// elements (and thus is invalid) when the expression is false.
//
// - The simpler definition
//
// #define STATIC_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1]
//
// does not work, as gcc supports variable-length arrays whose sizes
// are determined at run-time (this is gcc's extension and not part
// of the C++ standard). As a result, gcc fails to reject the
// following code with the simple definition:
//
// int foo;
// STATIC_ASSERT(foo, msg); // not supposed to compile as foo is
// // not a compile-time constant.
//
// - By using the type StaticAssert<(bool(expr))>, we ensures that
// expr is a compile-time constant. (Template arguments must be
// determined at compile-time.)
//
// - The outer parentheses in StaticAssert<(bool(expr))> are necessary
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
//
// StaticAssert<bool(expr)>
//
// instead, these compilers will refuse to compile
//
// STATIC_ASSERT(5 > 0, some_message);
//
// (They seem to think the ">" in "5 > 0" marks the end of the
// template argument list.)
//
// - The array size is (bool(expr) ? 1 : -1), instead of simply
//
// ((expr) ? 1 : -1).
//
// This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
#define CHECK(b) do { if (!(b)) assert(false); } while(0)
#define CHECK_EQ(a, b) CHECK((a) == (b))
#define CHECK_GE(a, b) CHECK((a) >= (b))
...
...
src/benchmark.cc
View file @
e390e4eb
...
...
@@ -80,10 +80,10 @@ static const char kBigIECUnits[] = "KMGTPEZY";
static
const
char
kSmallSIUnits
[]
=
"munpfazy"
;
// We require that all three arrays have the same size.
STATIC_ASSERT
(
arraysize
(
kBigSIUnits
)
==
arraysize
(
kBigIECUnits
),
SI_and_IEC_unit_arrays_must_be_the_same_size
);
STATIC_ASSERT
(
arraysize
(
kSmallSIUnits
)
==
arraysize
(
kBigSIUnits
),
Small_SI_and_Big_SI_unit_arrays_must_be_the_same_size
);
static_assert
(
arraysize
(
kBigSIUnits
)
==
arraysize
(
kBigIECUnits
),
"SI and IEC unit arrays must be the same size"
);
static_assert
(
arraysize
(
kSmallSIUnits
)
==
arraysize
(
kBigSIUnits
),
"Small SI and Big SI unit arrays must be the same size"
);
static
const
int
kUnitsSize
=
arraysize
(
kBigSIUnits
);
void
ToExponentAndMantissa
(
double
val
,
double
thresh
,
...
...
@@ -428,11 +428,11 @@ void UseRealTime() {
void
PrintUsageAndExit
()
{
fprintf
(
stdout
,
"benchmark [--benchmark_filter=<regex>]
\n
"
" [--benchmark_min_iters=<min_iters>]
\n
"
" [--benchmark_max_iters=<max_iters>]
\n
"
" [--benchmark_min_time=<min_time>]
\n
"
// TODO
" [--benchmark_min_iters=<min_iters>]\n"
// TODO
" [--benchmark_max_iters=<max_iters>]\n"
// TODO
" [--benchmark_min_time=<min_time>]\n"
// " [--benchmark_memory_usage]\n"
" [--benchmark_repetitions=<num_repetitions>]
\n
"
// TODO
" [--benchmark_repetitions=<num_repetitions>]\n"
" [--color_print={true|false}]
\n
"
" [--v=<verbosity>]
\n
"
);
exit
(
0
);
...
...
@@ -442,6 +442,7 @@ void ParseCommandLineFlags(int* argc, const char** argv) {
for
(
int
i
=
1
;
i
<
*
argc
;
++
i
)
{
if
(
ParseStringFlag
(
argv
[
i
],
"benchmark_filter"
,
&
FLAGS_benchmark_filter
)
||
/* TODO(dominic)
ParseInt32Flag(argv[i], "benchmark_min_iters",
&FLAGS_benchmark_min_iters) ||
ParseInt32Flag(argv[i], "benchmark_max_iters",
...
...
@@ -453,6 +454,7 @@ void ParseCommandLineFlags(int* argc, const char** argv) {
// &FLAGS_gbenchmark_memory_usage) ||
ParseInt32Flag(argv[i], "benchmark_repetitions",
&FLAGS_benchmark_repetitions) ||
*/
ParseBoolFlag
(
argv
[
i
],
"color_print"
,
&
FLAGS_color_print
)
||
ParseInt32Flag
(
argv
[
i
],
"v"
,
&
FLAGS_v
))
{
for
(
int
j
=
i
;
j
!=
*
argc
;
++
j
)
...
...
@@ -1189,9 +1191,8 @@ void Initialize(int* argc, const char** argv) {
pthread_key_create
(
&
thread_stats_key
,
DeleteThreadStats
);
thread_stats
=
new
internal
::
Benchmark
::
ThreadStats
();
walltime
::
Initialize
();
internal
::
Benchmark
::
MeasureOverhead
();
internal
::
ParseCommandLineFlags
(
argc
,
argv
);
internal
::
Benchmark
::
MeasureOverhead
();
}
}
// end namespace benchmark
src/colorprint.cc
View file @
e390e4eb
...
...
@@ -6,6 +6,7 @@
DECLARE_bool
(
color_print
);
namespace
benchmark
{
namespace
{
#ifdef OS_WINDOWS
typedef
WORD
PlatformColorCode
;
...
...
@@ -78,5 +79,5 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
#endif
va_end
(
args
);
}
}
// end namespace benchmark
src/colorprint.h
View file @
e390e4eb
#ifndef BENCHMARK_COLORPRINT_H_
#define BENCHMARK_COLORPRINT_H_
namespace
benchmark
{
enum
LogColor
{
COLOR_DEFAULT
,
COLOR_RED
,
...
...
@@ -13,5 +14,6 @@ enum LogColor {
};
void
ColorPrintf
(
LogColor
color
,
const
char
*
fmt
,
...);
}
// end namespace benchmark
#endif // BENCHMARK_COLORPRINT_H_
src/commandlineflags.h
View file @
e390e4eb
...
...
@@ -24,7 +24,6 @@
std::string FLAG(name) = (default_val)
namespace
benchmark
{
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
// to *value and returns true; otherwise leaves *value unchanged and returns
// false.
...
...
src/cycleclock.h
View file @
e390e4eb
...
...
@@ -44,7 +44,8 @@ extern "C" uint64_t __rdtsc();
// http://peter.kuscsik.com/wordpress/?p=14
// with modifications by m3b. See also
// https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h
struct
CycleClock
{
namespace
benchmark
{
namespace
cycleclock
{
// This should return the number of cycles since power-on. Thread-safe.
static
inline
int64_t
Now
()
{
#if defined(OS_MACOSX)
...
...
@@ -124,6 +125,7 @@ struct CycleClock {
#error You need to define CycleTimer for your OS and CPU
#endif
}
};
}
// end namespace cycleclock
}
// end namespace benchmark
#endif // BENCHMARK_CYCLECLOCK_H_
src/mutex_lock.h
View file @
e390e4eb
...
...
@@ -3,6 +3,7 @@
#include <pthread.h>
namespace
benchmark
{
class
mutex_lock
{
public
:
explicit
mutex_lock
(
pthread_mutex_t
*
mu
)
:
mu_
(
mu
)
{
...
...
@@ -16,5 +17,6 @@ class mutex_lock {
private
:
pthread_mutex_t
*
mu_
;
};
}
// end namespace benchmark
#endif // BENCHMARK_MUTEX_LOCK_H_
src/port.h
deleted
100644 → 0
View file @
403f3544
#ifndef BENCHMARK_PORT_H_
#define BENCHMARK_PORT_H_
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&);
#endif // BENCHMARK_PORT_H_
src/sleep.cc
View file @
e390e4eb
...
...
@@ -3,6 +3,7 @@
#include <time.h>
#include <errno.h>
namespace
benchmark
{
#ifdef OS_WINDOWS
// Window's _sleep takes milliseconds argument.
...
...
@@ -37,6 +38,5 @@ void SleepForSeconds(double seconds) {
}
#endif // OS_WINDOWS
}
// end namespace benchmark
src/sleep.h
View file @
e390e4eb
...
...
@@ -3,8 +3,10 @@
#include <stdint.h>
namespace
benchmark
{
void
SleepForMicroseconds
(
int64_t
microseconds
);
void
SleepForMilliseconds
(
int
milliseconds
);
void
SleepForSeconds
(
double
seconds
);
}
// end namespace benchmark
#endif // BENCHMARK_SLEEP_H_
src/stat.h
View file @
e390e4eb
...
...
@@ -5,6 +5,7 @@
#include <iostream>
#include <limits>
namespace
benchmark
{
template
<
typename
VType
,
typename
NumType
>
class
Stat1
;
...
...
@@ -302,5 +303,6 @@ inline std::ostream& operator <<(std::ostream& out,
<<
" max = "
<<
s
.
Max
()
<<
"}"
;
return
out
;
}
}
// end namespace benchmark
#endif // BENCHMARK_STAT_H_
src/sysinfo.cc
View file @
e390e4eb
...
...
@@ -18,6 +18,7 @@
#include "mutex_lock.h"
#include "sleep.h"
namespace
benchmark
{
namespace
{
pthread_once_t
cpuinfo_init
=
PTHREAD_ONCE_INIT
;
double
cpuinfo_cycles_per_second
=
1.0
;
...
...
@@ -30,9 +31,9 @@ int64_t EstimateCyclesPerSecond(const int estimate_time_ms) {
CHECK
(
estimate_time_ms
>
0
);
double
multiplier
=
1000.0
/
(
double
)
estimate_time_ms
;
// scale by this much
const
int64_t
start_ticks
=
CycleC
lock
::
Now
();
const
int64_t
start_ticks
=
cyclec
lock
::
Now
();
SleepForMilliseconds
(
estimate_time_ms
);
const
int64_t
guess
=
int64_t
(
multiplier
*
(
CycleC
lock
::
Now
()
-
start_ticks
));
const
int64_t
guess
=
int64_t
(
multiplier
*
(
cyclec
lock
::
Now
()
-
start_ticks
));
return
guess
;
}
...
...
@@ -334,4 +335,4 @@ int NumCPUs(void) {
pthread_once
(
&
cpuinfo_init
,
&
InitializeSystemInfo
);
return
cpuinfo_num_cpus
;
}
}
// end namespace benchmark
src/sysinfo.h
View file @
e390e4eb
#ifndef BENCHMARK_SYSINFO_H_
#define BENCHMARK_SYSINFO_H_
namespace
benchmark
{
double
MyCPUUsage
();
double
ChildrenCPUUsage
();
int
NumCPUs
();
double
CyclesPerSecond
();
}
// end namespace benchmark
#endif // BENCHMARK_SYSINFO_H_
src/walltime.cc
View file @
e390e4eb
...
...
@@ -12,6 +12,7 @@
#include "macros.h"
#include "sysinfo.h"
namespace
benchmark
{
namespace
walltime
{
namespace
{
const
double
kMaxErrorInterval
=
100e-6
;
...
...
@@ -77,9 +78,9 @@ void Initialize() {
max_interval_cycles
=
static_cast
<
int64_t
>
(
cycles_per_second
*
kMaxErrorInterval
);
do
{
base_cycletime
=
CycleC
lock
::
Now
();
base_cycletime
=
cyclec
lock
::
Now
();
base_walltime
=
Slow
();
}
while
(
CycleC
lock
::
Now
()
-
base_cycletime
>
max_interval_cycles
);
}
while
(
cyclec
lock
::
Now
()
-
base_cycletime
>
max_interval_cycles
);
// We are now sure that "base_walltime" and "base_cycletime" were produced
// within kMaxErrorInterval of one another.
...
...
@@ -97,7 +98,7 @@ WallTime Now() {
int64_t
ct
=
0
;
uint32_t
top_bits
=
0
;
do
{
ct
=
CycleC
lock
::
Now
();
ct
=
cyclec
lock
::
Now
();
int64_t
cycle_delta
=
ct
-
base_cycletime
;
result
=
base_walltime
+
cycle_delta
*
seconds_per_cycle
;
...
...
@@ -109,7 +110,7 @@ WallTime Now() {
}
now
=
Slow
();
}
while
(
CycleC
lock
::
Now
()
-
ct
>
max_interval_cycles
);
}
while
(
cyclec
lock
::
Now
()
-
ct
>
max_interval_cycles
);
// We are now sure that "now" and "result" were produced within
// kMaxErrorInterval of one another.
...
...
@@ -135,3 +136,4 @@ const char* Print(WallTime time, const char *format, bool local,
return
storage
;
}
}
// end namespace walltime
}
// end namespace benchmark
src/walltime.h
View file @
e390e4eb
#ifndef BENCHMARK_WALLTIME_H_
#define BENCHMARK_WALLTIME_H_
namespace
benchmark
{
typedef
double
WallTime
;
namespace
walltime
{
...
...
@@ -15,5 +16,6 @@ WallTime Now();
const
char
*
Print
(
WallTime
time
,
const
char
*
format
,
bool
local
,
char
*
storage
,
int
*
remainder_us
);
}
// end namespace walltime
}
// end namespace benchmark
#endif // BENCHMARK_WALLTIME_H_
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