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
e0441ef5
Commit
e0441ef5
authored
Oct 01, 2015
by
Eric Fiselier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into remove-check
parents
a69f566e
eeaec441
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
78 additions
and
33 deletions
+78
-33
README.md
README.md
+2
-1
benchmark_api.h
include/benchmark/benchmark_api.h
+8
-8
macros.h
include/benchmark/macros.h
+4
-0
reporter.h
include/benchmark/reporter.h
+1
-1
benchmark.cc
src/benchmark.cc
+4
-4
cycleclock.h
src/cycleclock.h
+3
-0
json_reporter.cc
src/json_reporter.cc
+0
-6
reporter.cc
src/reporter.cc
+1
-1
string_util.h
src/string_util.h
+2
-1
sysinfo.cc
src/sysinfo.cc
+3
-1
walltime.cc
src/walltime.cc
+41
-8
filter_test.cc
test/filter_test.cc
+1
-2
options_test.cc
test/options_test.cc
+8
-0
No files found.
README.md
View file @
e0441ef5
...
@@ -44,7 +44,8 @@ static void BM_memcpy(benchmark::State& state) {
...
@@ -44,7 +44,8 @@ static void BM_memcpy(benchmark::State& state) {
memset
(
src
,
'x'
,
state
.
range_x
());
memset
(
src
,
'x'
,
state
.
range_x
());
while
(
state
.
KeepRunning
())
while
(
state
.
KeepRunning
())
memcpy
(
dst
,
src
,
state
.
range_x
());
memcpy
(
dst
,
src
,
state
.
range_x
());
state
.
SetBytesProcessed
(
int64_t
(
state
.
iterations
)
*
int64_t
(
state
.
range_x
()));
state
.
SetBytesProcessed
(
int64_t
(
state
.
iterations
())
*
int64_t
(
state
.
range_x
()));
delete
[]
src
;
delete
[]
src
;
delete
[]
dst
;
delete
[]
dst
;
}
}
...
...
include/benchmark/benchmark_api.h
View file @
e0441ef5
...
@@ -42,7 +42,8 @@ static void BM_memcpy(benchmark::State& state) {
...
@@ -42,7 +42,8 @@ static void BM_memcpy(benchmark::State& state) {
memset(src, 'x', state.range_x());
memset(src, 'x', state.range_x());
while (state.KeepRunning())
while (state.KeepRunning())
memcpy(dst, src, state.range_x());
memcpy(dst, src, state.range_x());
state.SetBytesProcessed(int64_t_t(state.iterations) * int64(state.range_x()));
state.SetBytesProcessed(int64_t(state.iterations()) *
int64_t(state.range_x()));
delete[] src; delete[] dst;
delete[] src; delete[] dst;
}
}
BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
...
@@ -89,8 +90,7 @@ BENCHMARK(BM_SetInsert)->RangePair(1<<10, 8<<10, 1, 512);
...
@@ -89,8 +90,7 @@ BENCHMARK(BM_SetInsert)->RangePair(1<<10, 8<<10, 1, 512);
static void CustomArguments(benchmark::internal::Benchmark* b) {
static void CustomArguments(benchmark::internal::Benchmark* b) {
for (int i = 0; i <= 10; ++i)
for (int i = 0; i <= 10; ++i)
for (int j = 32; j <= 1024*1024; j *= 8)
for (int j = 32; j <= 1024*1024; j *= 8)
b = b->ArgPair(i, j);
b->ArgPair(i, j);
return b;
}
}
BENCHMARK(BM_SetInsert)->Apply(CustomArguments);
BENCHMARK(BM_SetInsert)->Apply(CustomArguments);
...
@@ -151,7 +151,7 @@ BENCHMARK(BM_MultiThreaded)->Threads(4);
...
@@ -151,7 +151,7 @@ BENCHMARK(BM_MultiThreaded)->Threads(4);
namespace
benchmark
{
namespace
benchmark
{
class
BenchmarkReporter
;
class
BenchmarkReporter
;
void
Initialize
(
int
*
argc
,
c
onst
c
har
**
argv
);
void
Initialize
(
int
*
argc
,
char
**
argv
);
// Otherwise, run all benchmarks specified by the --benchmark_filter flag,
// Otherwise, run all benchmarks specified by the --benchmark_filter flag,
// and exit after running the benchmarks.
// and exit after running the benchmarks.
...
@@ -593,10 +593,10 @@ protected: \
...
@@ -593,10 +593,10 @@ protected: \
// Helper macro to create a main routine in a test that runs the benchmarks
// Helper macro to create a main routine in a test that runs the benchmarks
#define BENCHMARK_MAIN()
\
#define BENCHMARK_MAIN() \
int main(int argc, c
onst char** argv) {
\
int main(int argc, c
har** argv) {
\
::benchmark::Initialize(&argc, argv);
\
::benchmark::Initialize(&argc, argv); \
::benchmark::RunSpecifiedBenchmarks();
\
::benchmark::RunSpecifiedBenchmarks(); \
}
}
#endif // BENCHMARK_BENCHMARK_API_H_
#endif // BENCHMARK_BENCHMARK_API_H_
include/benchmark/macros.h
View file @
e0441ef5
...
@@ -27,12 +27,16 @@
...
@@ -27,12 +27,16 @@
#if defined(__GNUC__)
#if defined(__GNUC__)
# define BENCHMARK_UNUSED __attribute__((unused))
# define BENCHMARK_UNUSED __attribute__((unused))
# define BENCHMARK_ALWAYS_INLINE __attribute__((always_inline))
# define BENCHMARK_ALWAYS_INLINE __attribute__((always_inline))
# define BENCHMARK_NOEXCEPT noexcept
#elif defined(_MSC_VER) && !defined(__clang__)
#elif defined(_MSC_VER) && !defined(__clang__)
# define BENCHMARK_UNUSED
# define BENCHMARK_UNUSED
# define BENCHMARK_ALWAYS_INLINE __forceinline
# define BENCHMARK_ALWAYS_INLINE __forceinline
# define BENCHMARK_NOEXCEPT
# define __func__ __FUNCTION__
#else
#else
# define BENCHMARK_UNUSED
# define BENCHMARK_UNUSED
# define BENCHMARK_ALWAYS_INLINE
# define BENCHMARK_ALWAYS_INLINE
# define BENCHMARK_NOEXCEPT
#endif
#endif
#if defined(__GNUC__)
#if defined(__GNUC__)
...
...
include/benchmark/reporter.h
View file @
e0441ef5
...
@@ -49,7 +49,7 @@ class BenchmarkReporter {
...
@@ -49,7 +49,7 @@ class BenchmarkReporter {
std
::
string
benchmark_name
;
std
::
string
benchmark_name
;
std
::
string
report_label
;
// Empty if not set by benchmark.
std
::
string
report_label
;
// Empty if not set by benchmark.
size
_t
iterations
;
int64
_t
iterations
;
double
real_accumulated_time
;
double
real_accumulated_time
;
double
cpu_accumulated_time
;
double
cpu_accumulated_time
;
...
...
src/benchmark.cc
View file @
e0441ef5
...
@@ -15,11 +15,11 @@
...
@@ -15,11 +15,11 @@
#include "benchmark/benchmark.h"
#include "benchmark/benchmark.h"
#include "internal_macros.h"
#include "internal_macros.h"
#include <sys/time.h>
#ifndef OS_WINDOWS
#ifndef OS_WINDOWS
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/resource.h>
#endif
#include <unistd.h>
#include <unistd.h>
#endif
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <cstring>
...
@@ -863,7 +863,7 @@ void PrintUsageAndExit() {
...
@@ -863,7 +863,7 @@ void PrintUsageAndExit() {
exit
(
0
);
exit
(
0
);
}
}
void
ParseCommandLineFlags
(
int
*
argc
,
c
onst
c
har
**
argv
)
{
void
ParseCommandLineFlags
(
int
*
argc
,
char
**
argv
)
{
using
namespace
benchmark
;
using
namespace
benchmark
;
for
(
int
i
=
1
;
i
<
*
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
*
argc
;
++
i
)
{
if
(
if
(
...
@@ -904,7 +904,7 @@ Benchmark* RegisterBenchmarkInternal(Benchmark* bench) {
...
@@ -904,7 +904,7 @@ Benchmark* RegisterBenchmarkInternal(Benchmark* bench) {
}
// end namespace internal
}
// end namespace internal
void
Initialize
(
int
*
argc
,
c
onst
c
har
**
argv
)
{
void
Initialize
(
int
*
argc
,
char
**
argv
)
{
internal
::
ParseCommandLineFlags
(
argc
,
argv
);
internal
::
ParseCommandLineFlags
(
argc
,
argv
);
internal
::
SetLogLevel
(
FLAGS_v
);
internal
::
SetLogLevel
(
FLAGS_v
);
// TODO remove this. It prints some output the first time it is called.
// TODO remove this. It prints some output the first time it is called.
...
...
src/cycleclock.h
View file @
e0441ef5
...
@@ -40,7 +40,10 @@
...
@@ -40,7 +40,10 @@
extern
"C"
uint64_t
__rdtsc
();
extern
"C"
uint64_t
__rdtsc
();
#pragma intrinsic(__rdtsc)
#pragma intrinsic(__rdtsc)
#endif
#endif
#ifndef OS_WINDOWS
#include <sys/time.h>
#include <sys/time.h>
#endif
namespace
benchmark
{
namespace
benchmark
{
// NOTE: only i386 and x86_64 have been well tested.
// NOTE: only i386 and x86_64 have been well tested.
...
...
src/json_reporter.cc
View file @
e0441ef5
...
@@ -44,12 +44,6 @@ std::string FormatKV(std::string const& key, int64_t value) {
...
@@ -44,12 +44,6 @@ std::string FormatKV(std::string const& key, int64_t value) {
return
ss
.
str
();
return
ss
.
str
();
}
}
std
::
string
FormatKV
(
std
::
string
const
&
key
,
std
::
size_t
value
)
{
std
::
stringstream
ss
;
ss
<<
'"'
<<
key
<<
"
\"
: "
<<
value
;
return
ss
.
str
();
}
int64_t
RoundDouble
(
double
v
)
{
int64_t
RoundDouble
(
double
v
)
{
return
static_cast
<
int64_t
>
(
v
+
0.5
);
return
static_cast
<
int64_t
>
(
v
+
0.5
);
}
}
...
...
src/reporter.cc
View file @
e0441ef5
...
@@ -33,7 +33,7 @@ void BenchmarkReporter::ComputeStats(
...
@@ -33,7 +33,7 @@ void BenchmarkReporter::ComputeStats(
Stat1_d
items_per_second_stat
;
Stat1_d
items_per_second_stat
;
// All repetitions should be run with the same number of iterations so we
// All repetitions should be run with the same number of iterations so we
// can take this information from the first benchmark.
// can take this information from the first benchmark.
std
::
size
_t
const
run_iterations
=
reports
.
front
().
iterations
;
int64
_t
const
run_iterations
=
reports
.
front
().
iterations
;
// Populate the accumulators.
// Populate the accumulators.
for
(
Run
const
&
run
:
reports
)
{
for
(
Run
const
&
run
:
reports
)
{
...
...
src/string_util.h
View file @
e0441ef5
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include <string>
#include <string>
#include <sstream>
#include <sstream>
#include <utility>
#include <utility>
#include "internal_macros.h"
namespace
benchmark
{
namespace
benchmark
{
...
@@ -14,7 +15,7 @@ std::string HumanReadableNumber(double n);
...
@@ -14,7 +15,7 @@ std::string HumanReadableNumber(double n);
std
::
string
StringPrintF
(
const
char
*
format
,
...);
std
::
string
StringPrintF
(
const
char
*
format
,
...);
inline
std
::
ostream
&
inline
std
::
ostream
&
StringCatImp
(
std
::
ostream
&
out
)
noexcept
StringCatImp
(
std
::
ostream
&
out
)
BENCHMARK_NOEXCEPT
{
{
return
out
;
return
out
;
}
}
...
...
src/sysinfo.cc
View file @
e0441ef5
...
@@ -305,7 +305,7 @@ static double MyCPUUsageRUsage() {
...
@@ -305,7 +305,7 @@ static double MyCPUUsageRUsage() {
user
.
HighPart
=
user_time
.
dwHighDateTime
;
user
.
HighPart
=
user_time
.
dwHighDateTime
;
user
.
LowPart
=
user_time
.
dwLowDateTime
;
user
.
LowPart
=
user_time
.
dwLowDateTime
;
return
(
static_cast
<
double
>
(
kernel
.
QuadPart
)
+
return
(
static_cast
<
double
>
(
kernel
.
QuadPart
)
+
static_cast
<
double
>
(
user
.
QuadPart
))
/
1.0E
-7
;
static_cast
<
double
>
(
user
.
QuadPart
))
*
1e
-7
;
#endif // OS_WINDOWS
#endif // OS_WINDOWS
}
}
...
@@ -394,6 +394,7 @@ int NumCPUs(void) {
...
@@ -394,6 +394,7 @@ int NumCPUs(void) {
: nullptr)
: nullptr)
bool
CpuScalingEnabled
()
{
bool
CpuScalingEnabled
()
{
#ifndef OS_WINDOWS
// On Linux, the CPUfreq subsystem exposes CPU information as files on the
// On Linux, the CPUfreq subsystem exposes CPU information as files on the
// local file system. If reading the exported files fails, then we may not be
// local file system. If reading the exported files fails, then we may not be
// running on Linux, so we silently ignore all the read errors.
// running on Linux, so we silently ignore all the read errors.
...
@@ -407,6 +408,7 @@ bool CpuScalingEnabled() {
...
@@ -407,6 +408,7 @@ bool CpuScalingEnabled() {
fclose
(
file
);
fclose
(
file
);
if
(
memprefix
(
buff
,
bytes_read
,
"performance"
)
==
nullptr
)
return
true
;
if
(
memprefix
(
buff
,
bytes_read
,
"performance"
)
==
nullptr
)
return
true
;
}
}
#endif
return
false
;
return
false
;
}
}
...
...
src/walltime.cc
View file @
e0441ef5
...
@@ -12,9 +12,16 @@
...
@@ -12,9 +12,16 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
#include "benchmark/macros.h"
#include "internal_macros.h"
#include "walltime.h"
#include "walltime.h"
#if defined(OS_WINDOWS)
#include <time.h>
#include <winsock.h> // for timeval
#else
#include <sys/time.h>
#include <sys/time.h>
#endif
#include <cstdio>
#include <cstdio>
#include <cstdint>
#include <cstdint>
...
@@ -50,7 +57,7 @@ struct ChooseSteadyClock<false> {
...
@@ -50,7 +57,7 @@ struct ChooseSteadyClock<false> {
struct
ChooseClockType
{
struct
ChooseClockType
{
#if defined(HAVE_STEADY_CLOCK)
#if defined(HAVE_STEADY_CLOCK)
typedef
typename
ChooseSteadyClock
<>::
type
type
;
typedef
ChooseSteadyClock
<>::
type
type
;
#else
#else
typedef
std
::
chrono
::
high_resolution_clock
type
;
typedef
std
::
chrono
::
high_resolution_clock
type
;
#endif
#endif
...
@@ -86,7 +93,22 @@ private:
...
@@ -86,7 +93,22 @@ private:
WallTime
Slow
()
const
{
WallTime
Slow
()
const
{
struct
timeval
tv
;
struct
timeval
tv
;
#if defined(OS_WINDOWS)
FILETIME
file_time
;
SYSTEMTIME
system_time
;
ULARGE_INTEGER
ularge
;
const
unsigned
__int64
epoch
=
116444736000000000LL
;
GetSystemTime
(
&
system_time
);
SystemTimeToFileTime
(
&
system_time
,
&
file_time
);
ularge
.
LowPart
=
file_time
.
dwLowDateTime
;
ularge
.
HighPart
=
file_time
.
dwHighDateTime
;
tv
.
tv_sec
=
(
long
)((
ularge
.
QuadPart
-
epoch
)
/
(
10L
*
1000
*
1000
));
tv
.
tv_usec
=
(
long
)(
system_time
.
wMilliseconds
*
1000
);
#else
gettimeofday
(
&
tv
,
nullptr
);
gettimeofday
(
&
tv
,
nullptr
);
#endif
return
tv
.
tv_sec
+
tv
.
tv_usec
*
1e-6
;
return
tv
.
tv_sec
+
tv
.
tv_usec
*
1e-6
;
}
}
...
@@ -94,8 +116,6 @@ private:
...
@@ -94,8 +116,6 @@ private:
static_assert
(
sizeof
(
float
)
<=
sizeof
(
int32_t
),
static_assert
(
sizeof
(
float
)
<=
sizeof
(
int32_t
),
"type sizes don't allow the drift_adjust hack"
);
"type sizes don't allow the drift_adjust hack"
);
static
constexpr
double
kMaxErrorInterval
=
100e-6
;
WallTime
base_walltime_
;
WallTime
base_walltime_
;
int64_t
base_cycletime_
;
int64_t
base_cycletime_
;
int64_t
cycles_per_second_
;
int64_t
cycles_per_second_
;
...
@@ -141,6 +161,7 @@ WallTimeImp::WallTimeImp()
...
@@ -141,6 +161,7 @@ WallTimeImp::WallTimeImp()
cycles_per_second_
(
0
),
seconds_per_cycle_
(
0.0
),
cycles_per_second_
(
0
),
seconds_per_cycle_
(
0.0
),
last_adjust_time_
(
0
),
drift_adjust_
(
0
),
last_adjust_time_
(
0
),
drift_adjust_
(
0
),
max_interval_cycles_
(
0
)
{
max_interval_cycles_
(
0
)
{
const
double
kMaxErrorInterval
=
100e-6
;
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_
;
...
@@ -207,15 +228,27 @@ std::string DateTimeString(bool local) {
...
@@ -207,15 +228,27 @@ std::string DateTimeString(bool local) {
typedef
std
::
chrono
::
system_clock
Clock
;
typedef
std
::
chrono
::
system_clock
Clock
;
std
::
time_t
now
=
Clock
::
to_time_t
(
Clock
::
now
());
std
::
time_t
now
=
Clock
::
to_time_t
(
Clock
::
now
());
char
storage
[
128
];
char
storage
[
128
];
std
::
size_t
written
;
std
::
tm
timeinfo
;
std
::
memset
(
&
timeinfo
,
0
,
sizeof
(
std
::
tm
));
if
(
local
)
{
if
(
local
)
{
localtime_r
(
&
now
,
&
timeinfo
);
#if defined(OS_WINDOWS)
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%x %X"
,
::
localtime
(
&
now
));
#else
std
::
tm
timeinfo
;
std
::
memset
(
&
timeinfo
,
0
,
sizeof
(
std
::
tm
));
::
localtime_r
(
&
now
,
&
timeinfo
);
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%F %T"
,
&
timeinfo
);
#endif
}
else
{
}
else
{
gmtime_r
(
&
now
,
&
timeinfo
);
#if defined(OS_WINDOWS)
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%x %X"
,
::
gmtime
(
&
now
));
#else
std
::
tm
timeinfo
;
std
::
memset
(
&
timeinfo
,
0
,
sizeof
(
std
::
tm
));
::
gmtime_r
(
&
now
,
&
timeinfo
);
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%F %T"
,
&
timeinfo
);
#endif
}
}
std
::
size_t
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%F %T"
,
&
timeinfo
);
CHECK
(
written
<
arraysize
(
storage
));
CHECK
(
written
<
arraysize
(
storage
));
((
void
)
written
);
// prevent unused variable in optimized mode.
((
void
)
written
);
// prevent unused variable in optimized mode.
return
std
::
string
(
storage
);
return
std
::
string
(
storage
);
...
...
test/filter_test.cc
View file @
e0441ef5
...
@@ -67,7 +67,7 @@ BENCHMARK(BM_FooBa);
...
@@ -67,7 +67,7 @@ BENCHMARK(BM_FooBa);
int
main
(
int
argc
,
c
onst
c
har
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
benchmark
::
Initialize
(
&
argc
,
argv
);
benchmark
::
Initialize
(
&
argc
,
argv
);
TestReporter
test_reporter
;
TestReporter
test_reporter
;
...
@@ -82,4 +82,3 @@ int main(int argc, const char* argv[]) {
...
@@ -82,4 +82,3 @@ int main(int argc, const char* argv[]) {
return
-
1
;
return
-
1
;
}
}
}
}
test/options_test.cc
View file @
e0441ef5
...
@@ -15,4 +15,12 @@ BENCHMARK(BM_basic)->UseRealTime();
...
@@ -15,4 +15,12 @@ BENCHMARK(BM_basic)->UseRealTime();
BENCHMARK
(
BM_basic
)
->
ThreadRange
(
2
,
4
);
BENCHMARK
(
BM_basic
)
->
ThreadRange
(
2
,
4
);
BENCHMARK
(
BM_basic
)
->
ThreadPerCpu
();
BENCHMARK
(
BM_basic
)
->
ThreadPerCpu
();
void
CustomArgs
(
benchmark
::
internal
::
Benchmark
*
b
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
b
->
Arg
(
i
);
}
}
BENCHMARK
(
BM_basic
)
->
Apply
(
CustomArgs
);
BENCHMARK_MAIN
()
BENCHMARK_MAIN
()
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