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
d07372e6
Unverified
Commit
d07372e6
authored
May 29, 2018
by
Dominic Hamon
Committed by
GitHub
May 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang-format run on the benchmark header (#606)
parent
7b8d0249
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
54 deletions
+44
-54
benchmark.h
include/benchmark/benchmark.h
+44
-54
No files found.
include/benchmark/benchmark.h
View file @
d07372e6
...
@@ -164,7 +164,6 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
...
@@ -164,7 +164,6 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#ifndef BENCHMARK_BENCHMARK_H_
#ifndef BENCHMARK_BENCHMARK_H_
#define BENCHMARK_BENCHMARK_H_
#define BENCHMARK_BENCHMARK_H_
// The _MSVC_LANG check should detect Visual Studio 2015 Update 3 and newer.
// The _MSVC_LANG check should detect Visual Studio 2015 Update 3 and newer.
#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
#define BENCHMARK_HAS_CXX11
#define BENCHMARK_HAS_CXX11
...
@@ -176,14 +175,14 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
...
@@ -176,14 +175,14 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#include <cassert>
#include <cassert>
#include <cstddef>
#include <cstddef>
#include <iosfwd>
#include <iosfwd>
#include <string>
#include <vector>
#include <map>
#include <map>
#include <set>
#include <set>
#include <string>
#include <vector>
#if defined(BENCHMARK_HAS_CXX11)
#if defined(BENCHMARK_HAS_CXX11)
#include <type_traits>
#include <initializer_list>
#include <initializer_list>
#include <type_traits>
#include <utility>
#include <utility>
#endif
#endif
...
@@ -233,7 +232,9 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
...
@@ -233,7 +232,9 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#else
#else
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
#define BENCHMARK_DEPRECATED_MSG(msg)
#define BENCHMARK_DEPRECATED_MSG(msg)
#define BENCHMARK_WARNING_MSG(msg) __pragma(message(__FILE__ "(" BENCHMARK_INTERNAL_TOSTRING(__LINE__) ") : warning note: " msg))
#define BENCHMARK_WARNING_MSG(msg) \
__pragma(message(__FILE__ "(" BENCHMARK_INTERNAL_TOSTRING( \
__LINE__) ") : warning note: " msg))
#endif
#endif
#if defined(__GNUC__) && !defined(__clang__)
#if defined(__GNUC__) && !defined(__clang__)
...
@@ -290,21 +291,18 @@ BENCHMARK_UNUSED static int stream_init_anchor = InitializeStreams();
...
@@ -290,21 +291,18 @@ BENCHMARK_UNUSED static int stream_init_anchor = InitializeStreams();
}
// namespace internal
}
// namespace internal
#if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || \
#if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || \
defined(__EMSCRIPTEN__)
defined(__EMSCRIPTEN__)
#
define BENCHMARK_HAS_NO_INLINE_ASSEMBLY
#define BENCHMARK_HAS_NO_INLINE_ASSEMBLY
#endif
#endif
// The DoNotOptimize(...) function can be used to prevent a value or
// The DoNotOptimize(...) function can be used to prevent a value or
// expression from being optimized away by the compiler. This function is
// expression from being optimized away by the compiler. This function is
// intended to add little to no overhead.
// intended to add little to no overhead.
// See: https://youtu.be/nXaxk27zwlk?t=2441
// See: https://youtu.be/nXaxk27zwlk?t=2441
#ifndef BENCHMARK_HAS_NO_INLINE_ASSEMBLY
#ifndef BENCHMARK_HAS_NO_INLINE_ASSEMBLY
template
<
class
Tp
>
template
<
class
Tp
>
inline
BENCHMARK_ALWAYS_INLINE
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
void
DoNotOptimize
(
Tp
const
&
value
)
{
asm
volatile
(
""
:
:
"r,m"
(
value
)
:
"memory"
);
asm
volatile
(
""
:
:
"r,m"
(
value
)
:
"memory"
);
}
}
...
@@ -329,9 +327,7 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
...
@@ -329,9 +327,7 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
_ReadWriteBarrier
();
_ReadWriteBarrier
();
}
}
inline
BENCHMARK_ALWAYS_INLINE
void
ClobberMemory
()
{
inline
BENCHMARK_ALWAYS_INLINE
void
ClobberMemory
()
{
_ReadWriteBarrier
();
}
_ReadWriteBarrier
();
}
#else
#else
template
<
class
Tp
>
template
<
class
Tp
>
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
...
@@ -340,12 +336,9 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
...
@@ -340,12 +336,9 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
// FIXME Add ClobberMemory() for non-gnu and non-msvc compilers
// FIXME Add ClobberMemory() for non-gnu and non-msvc compilers
#endif
#endif
// This class is used for user-defined counters.
// This class is used for user-defined counters.
class
Counter
{
class
Counter
{
public
:
public
:
enum
Flags
{
enum
Flags
{
kDefaults
=
0
,
kDefaults
=
0
,
// Mark the counter as a rate. It will be presented divided
// Mark the counter as a rate. It will be presented divided
...
@@ -355,7 +348,7 @@ public:
...
@@ -355,7 +348,7 @@ public:
// presented divided by the number of threads.
// presented divided by the number of threads.
kAvgThreads
=
2
,
kAvgThreads
=
2
,
// Mark the counter as a thread-average rate. See above.
// Mark the counter as a thread-average rate. See above.
kAvgThreadsRate
=
kIsRate
|
kAvgThreads
kAvgThreadsRate
=
kIsRate
|
kAvgThreads
};
};
double
value
;
double
value
;
...
@@ -364,15 +357,13 @@ public:
...
@@ -364,15 +357,13 @@ public:
BENCHMARK_ALWAYS_INLINE
BENCHMARK_ALWAYS_INLINE
Counter
(
double
v
=
0
.,
Flags
f
=
kDefaults
)
:
value
(
v
),
flags
(
f
)
{}
Counter
(
double
v
=
0
.,
Flags
f
=
kDefaults
)
:
value
(
v
),
flags
(
f
)
{}
BENCHMARK_ALWAYS_INLINE
operator
double
const
&
()
const
{
return
value
;
}
BENCHMARK_ALWAYS_INLINE
operator
double
const
&
()
const
{
return
value
;
}
BENCHMARK_ALWAYS_INLINE
operator
double
&
()
{
return
value
;
}
BENCHMARK_ALWAYS_INLINE
operator
double
&
()
{
return
value
;
}
};
};
// This is the container for the user-defined counters.
// This is the container for the user-defined counters.
typedef
std
::
map
<
std
::
string
,
Counter
>
UserCounters
;
typedef
std
::
map
<
std
::
string
,
Counter
>
UserCounters
;
// TimeUnit is passed to a benchmark in order to specify the order of magnitude
// TimeUnit is passed to a benchmark in order to specify the order of magnitude
// for the measured time.
// for the measured time.
enum
TimeUnit
{
kNanosecond
,
kMicrosecond
,
kMillisecond
};
enum
TimeUnit
{
kNanosecond
,
kMicrosecond
,
kMillisecond
};
...
@@ -408,11 +399,9 @@ enum ReportMode
...
@@ -408,11 +399,9 @@ enum ReportMode
:
unsigned
:
unsigned
#else
#else
#endif
#endif
{
{
RM_Unspecified
,
// The mode has not been manually specified
RM_Unspecified
,
// The mode has not been manually specified
RM_Default
,
// The mode is user-specified as default.
RM_Default
,
// The mode is user-specified as default.
RM_ReportAggregatesOnly
RM_ReportAggregatesOnly
};
};
}
// namespace internal
}
// namespace internal
// State is passed to a running Benchmark and contains state for the
// State is passed to a running Benchmark and contains state for the
...
@@ -581,8 +570,8 @@ class State {
...
@@ -581,8 +570,8 @@ class State {
return
max_iterations
-
total_iterations_
+
batch_leftover_
;
return
max_iterations
-
total_iterations_
+
batch_leftover_
;
}
}
private
:
// items we expect on the first cache line (ie 64 bytes of the struct)
private
:
// items we expect on the first cache line (ie 64 bytes of the struct)
// When total_iterations_ is 0, KeepRunning() and friends will return false.
// When total_iterations_ is 0, KeepRunning() and friends will return false.
// May be larger than max_iterations.
// May be larger than max_iterations.
size_t
total_iterations_
;
size_t
total_iterations_
;
...
@@ -592,15 +581,15 @@ private: // items we expect on the first cache line (ie 64 bytes of the struct)
...
@@ -592,15 +581,15 @@ private: // items we expect on the first cache line (ie 64 bytes of the struct)
// completed_iterations_ accurately.
// completed_iterations_ accurately.
size_t
batch_leftover_
;
size_t
batch_leftover_
;
public
:
public
:
const
size_t
max_iterations
;
const
size_t
max_iterations
;
private
:
private
:
bool
started_
;
bool
started_
;
bool
finished_
;
bool
finished_
;
bool
error_occurred_
;
bool
error_occurred_
;
private
:
// items we don't need on the first cache line
private
:
// items we don't need on the first cache line
std
::
vector
<
int64_t
>
range_
;
std
::
vector
<
int64_t
>
range_
;
int64_t
bytes_processed_
;
int64_t
bytes_processed_
;
...
@@ -616,7 +605,6 @@ private: // items we don't need on the first cache line
...
@@ -616,7 +605,6 @@ private: // items we don't need on the first cache line
// Number of threads concurrently executing the benchmark.
// Number of threads concurrently executing the benchmark.
const
int
threads
;
const
int
threads
;
// TODO(EricWF) make me private
// TODO(EricWF) make me private
State
(
size_t
max_iters
,
const
std
::
vector
<
int64_t
>&
ranges
,
int
thread_i
,
State
(
size_t
max_iters
,
const
std
::
vector
<
int64_t
>&
ranges
,
int
thread_i
,
int
n_threads
,
internal
::
ThreadTimer
*
timer
,
int
n_threads
,
internal
::
ThreadTimer
*
timer
,
...
@@ -633,18 +621,16 @@ private: // items we don't need on the first cache line
...
@@ -633,18 +621,16 @@ private: // items we don't need on the first cache line
BENCHMARK_DISALLOW_COPY_AND_ASSIGN
(
State
);
BENCHMARK_DISALLOW_COPY_AND_ASSIGN
(
State
);
};
};
inline
BENCHMARK_ALWAYS_INLINE
inline
BENCHMARK_ALWAYS_INLINE
bool
State
::
KeepRunning
()
{
bool
State
::
KeepRunning
()
{
return
KeepRunningInternal
(
1
,
/*is_batch=*/
false
);
return
KeepRunningInternal
(
1
,
/*is_batch=*/
false
);
}
}
inline
BENCHMARK_ALWAYS_INLINE
inline
BENCHMARK_ALWAYS_INLINE
bool
State
::
KeepRunningBatch
(
size_t
n
)
{
bool
State
::
KeepRunningBatch
(
size_t
n
)
{
return
KeepRunningInternal
(
n
,
/*is_batch=*/
true
);
return
KeepRunningInternal
(
n
,
/*is_batch=*/
true
);
}
}
inline
BENCHMARK_ALWAYS_INLINE
inline
BENCHMARK_ALWAYS_INLINE
bool
State
::
KeepRunningInternal
(
size_t
n
,
bool
State
::
KeepRunningInternal
(
size_t
n
,
bool
is_batch
)
{
bool
is_batch
)
{
// total_iterations_ is set to 0 by the constructor, and always set to a
// total_iterations_ is set to 0 by the constructor, and always set to a
// nonzero value by StartKepRunning().
// nonzero value by StartKepRunning().
assert
(
n
>
0
);
assert
(
n
>
0
);
...
@@ -657,7 +643,7 @@ bool State::KeepRunningInternal(size_t n, bool is_batch) {
...
@@ -657,7 +643,7 @@ bool State::KeepRunningInternal(size_t n, bool is_batch) {
if
(
!
started_
)
{
if
(
!
started_
)
{
StartKeepRunning
();
StartKeepRunning
();
if
(
!
error_occurred_
&&
total_iterations_
>=
n
)
{
if
(
!
error_occurred_
&&
total_iterations_
>=
n
)
{
total_iterations_
-=
n
;
total_iterations_
-=
n
;
return
true
;
return
true
;
}
}
}
}
...
@@ -1122,7 +1108,7 @@ class Fixture : public internal::Benchmark {
...
@@ -1122,7 +1108,7 @@ class Fixture : public internal::Benchmark {
class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \
class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \
public: \
public: \
BaseClass##_##Method##_Benchmark() : BaseClass<a>() { \
BaseClass##_##Method##_Benchmark() : BaseClass<a>() { \
this->SetName(#BaseClass
"<" #a ">/" #Method);
\
this->SetName(#BaseClass
"<" #a ">/" #Method);
\
} \
} \
\
\
protected: \
protected: \
...
@@ -1133,7 +1119,7 @@ class Fixture : public internal::Benchmark {
...
@@ -1133,7 +1119,7 @@ class Fixture : public internal::Benchmark {
class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \
class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \
public: \
public: \
BaseClass##_##Method##_Benchmark() : BaseClass<a, b>() { \
BaseClass##_##Method##_Benchmark() : BaseClass<a, b>() { \
this->SetName(#BaseClass
"<" #a "," #b ">/" #Method);
\
this->SetName(#BaseClass
"<" #a "," #b ">/" #Method);
\
} \
} \
\
\
protected: \
protected: \
...
@@ -1145,14 +1131,15 @@ class Fixture : public internal::Benchmark {
...
@@ -1145,14 +1131,15 @@ class Fixture : public internal::Benchmark {
class BaseClass##_##Method##_Benchmark : public BaseClass<__VA_ARGS__> { \
class BaseClass##_##Method##_Benchmark : public BaseClass<__VA_ARGS__> { \
public: \
public: \
BaseClass##_##Method##_Benchmark() : BaseClass<__VA_ARGS__>() { \
BaseClass##_##Method##_Benchmark() : BaseClass<__VA_ARGS__>() { \
this->SetName(#BaseClass
"<" #__VA_ARGS__ ">/" #Method);
\
this->SetName(#BaseClass
"<" #__VA_ARGS__ ">/" #Method);
\
} \
} \
\
\
protected: \
protected: \
virtual void BenchmarkCase(::benchmark::State&); \
virtual void BenchmarkCase(::benchmark::State&); \
};
};
#else
#else
#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(n, a) BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(n, a)
#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(n, a) \
BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(n, a)
#endif
#endif
#define BENCHMARK_DEFINE_F(BaseClass, Method) \
#define BENCHMARK_DEFINE_F(BaseClass, Method) \
...
@@ -1172,7 +1159,8 @@ class Fixture : public internal::Benchmark {
...
@@ -1172,7 +1159,8 @@ class Fixture : public internal::Benchmark {
BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(BaseClass, Method, __VA_ARGS__) \
BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(BaseClass, Method, __VA_ARGS__) \
void BaseClass##_##Method##_Benchmark::BenchmarkCase
void BaseClass##_##Method##_Benchmark::BenchmarkCase
#else
#else
#define BENCHMARK_TEMPLATE_DEFINE_F(BaseClass, Method, a) BENCHMARK_TEMPLATE1_DEFINE_F(BaseClass, Method, a)
#define BENCHMARK_TEMPLATE_DEFINE_F(BaseClass, Method, a) \
BENCHMARK_TEMPLATE1_DEFINE_F(BaseClass, Method, a)
#endif
#endif
#define BENCHMARK_REGISTER_F(BaseClass, Method) \
#define BENCHMARK_REGISTER_F(BaseClass, Method) \
...
@@ -1204,7 +1192,8 @@ class Fixture : public internal::Benchmark {
...
@@ -1204,7 +1192,8 @@ class Fixture : public internal::Benchmark {
BENCHMARK_REGISTER_F(BaseClass, Method); \
BENCHMARK_REGISTER_F(BaseClass, Method); \
void BaseClass##_##Method##_Benchmark::BenchmarkCase
void BaseClass##_##Method##_Benchmark::BenchmarkCase
#else
#else
#define BENCHMARK_TEMPLATE_F(BaseClass, Method, a) BENCHMARK_TEMPLATE1_F(BaseClass, Method, a)
#define BENCHMARK_TEMPLATE_F(BaseClass, Method, a) \
BENCHMARK_TEMPLATE1_F(BaseClass, Method, a)
#endif
#endif
// 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
...
@@ -1216,7 +1205,6 @@ class Fixture : public internal::Benchmark {
...
@@ -1216,7 +1205,6 @@ class Fixture : public internal::Benchmark {
} \
} \
int main(int, char**)
int main(int, char**)
// ------------------------------------------------------
// ------------------------------------------------------
// Benchmark Reporters
// Benchmark Reporters
...
@@ -1253,7 +1241,7 @@ class BenchmarkReporter {
...
@@ -1253,7 +1241,7 @@ class BenchmarkReporter {
CPUInfo
const
&
cpu_info
;
CPUInfo
const
&
cpu_info
;
// The number of chars in the longest benchmark name.
// The number of chars in the longest benchmark name.
size_t
name_field_width
;
size_t
name_field_width
;
static
const
char
*
executable_name
;
static
const
char
*
executable_name
;
Context
();
Context
();
};
};
...
@@ -1376,17 +1364,19 @@ class BenchmarkReporter {
...
@@ -1376,17 +1364,19 @@ class BenchmarkReporter {
// 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().
class
ConsoleReporter
:
public
BenchmarkReporter
{
class
ConsoleReporter
:
public
BenchmarkReporter
{
public
:
public
:
enum
OutputOptions
{
enum
OutputOptions
{
OO_None
=
0
,
OO_None
=
0
,
OO_Color
=
1
,
OO_Color
=
1
,
OO_Tabular
=
2
,
OO_Tabular
=
2
,
OO_ColorTabular
=
OO_Color
|
OO_Tabular
,
OO_ColorTabular
=
OO_Color
|
OO_Tabular
,
OO_Defaults
=
OO_ColorTabular
OO_Defaults
=
OO_ColorTabular
};
};
explicit
ConsoleReporter
(
OutputOptions
opts_
=
OO_Defaults
)
explicit
ConsoleReporter
(
OutputOptions
opts_
=
OO_Defaults
)
:
output_options_
(
opts_
),
name_field_width_
(
0
),
:
output_options_
(
opts_
),
prev_counters_
(),
printed_header_
(
false
)
{}
name_field_width_
(
0
),
prev_counters_
(),
printed_header_
(
false
)
{}
virtual
bool
ReportContext
(
const
Context
&
context
);
virtual
bool
ReportContext
(
const
Context
&
context
);
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
reports
);
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
reports
);
...
@@ -1425,7 +1415,7 @@ class BENCHMARK_DEPRECATED_MSG("The CSV Reporter will be removed in a future rel
...
@@ -1425,7 +1415,7 @@ class BENCHMARK_DEPRECATED_MSG("The CSV Reporter will be removed in a future rel
void
PrintRunData
(
const
Run
&
report
);
void
PrintRunData
(
const
Run
&
report
);
bool
printed_header_
;
bool
printed_header_
;
std
::
set
<
std
::
string
>
user_counter_names_
;
std
::
set
<
std
::
string
>
user_counter_names_
;
};
};
inline
const
char
*
GetTimeUnitString
(
TimeUnit
unit
)
{
inline
const
char
*
GetTimeUnitString
(
TimeUnit
unit
)
{
...
...
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