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
11e30435
Commit
11e30435
authored
Jun 02, 2016
by
Ismael
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checked format before pull request
parent
212cfe1c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
98 deletions
+98
-98
benchmark_api.h
include/benchmark/benchmark_api.h
+8
-8
reporter.h
include/benchmark/reporter.h
+5
-5
benchmark.cc
src/benchmark.cc
+75
-75
complexity.cc
src/complexity.cc
+2
-2
complexity.h
src/complexity.h
+7
-7
json_reporter.cc
src/json_reporter.cc
+1
-1
No files found.
include/benchmark/benchmark_api.h
View file @
11e30435
...
...
@@ -261,16 +261,16 @@ typedef double(BigOFunc)(size_t);
class
State
{
public
:
State
(
size_t
max_iters
,
bool
has_x
,
int
x
,
bool
has_y
,
int
y
,
int
thread_i
,
int
n_threads
);
int
thread_i
,
int
n_threads
);
// Returns true if
f
the benchmark should continue through another iteration.
// Returns true if the benchmark should continue through another iteration.
// NOTE: A benchmark may not return from the test until KeepRunning() has
// returned false.
bool
KeepRunning
()
{
if
(
BENCHMARK_BUILTIN_EXPECT
(
!
started_
,
false
))
{
assert
(
!
finished_
);
started_
=
true
;
ResumeTiming
();
assert
(
!
finished_
);
started_
=
true
;
ResumeTiming
();
}
bool
const
res
=
total_iterations_
++
<
max_iterations
;
if
(
BENCHMARK_BUILTIN_EXPECT
(
!
res
,
false
))
{
...
...
@@ -365,7 +365,7 @@ public:
// represent the length of N.
BENCHMARK_ALWAYS_INLINE
void
SetComplexityN
(
size_t
complexity_n
)
{
complexity_n_
=
complexity_n
;
complexity_n_
=
complexity_n
;
}
BENCHMARK_ALWAYS_INLINE
...
...
@@ -539,11 +539,11 @@ public:
// to control how many iterations are run, and in the printing of items/second
// or MB/second values.
Benchmark
*
UseManualTime
();
// Set the asymptotic computational complexity for the benchmark. If called
// the asymptotic computational complexity will be shown on the output.
Benchmark
*
Complexity
(
BigO
complexity
=
benchmark
::
oAuto
);
// Set the asymptotic computational complexity for the benchmark. If called
// the asymptotic computational complexity will be shown on the output.
Benchmark
*
Complexity
(
BigOFunc
*
complexity
);
...
...
include/benchmark/reporter.h
View file @
11e30435
...
...
@@ -83,12 +83,12 @@ class BenchmarkReporter {
// This is set to 0.0 if memory tracing is not enabled.
double
max_heapbytes_used
;
// Keep track of arguments to compute asymptotic complexity
BigO
complexity
;
BigOFunc
*
complexity_lambda
;
size_t
complexity_n
;
// Inform print function whether the current run is a complexity report
bool
report_big_o
;
bool
report_rms
;
...
...
@@ -114,7 +114,7 @@ class BenchmarkReporter {
// 'reports' contains additional entries representing the asymptotic
// complexity and RMS of that benchmark family.
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
report
)
=
0
;
// Called once and only once after ever group of benchmarks is run and
// reported.
virtual
void
Finalize
()
{}
...
...
@@ -156,11 +156,11 @@ private:
// Simple reporter that outputs benchmark data to the console. This is the
// default reporter used by RunSpecifiedBenchmarks().
class
ConsoleReporter
:
public
BenchmarkReporter
{
public
:
public
:
virtual
bool
ReportContext
(
const
Context
&
context
);
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
reports
);
protected
:
protected
:
virtual
void
PrintRunData
(
const
Run
&
report
);
size_t
name_field_width_
;
...
...
src/benchmark.cc
View file @
11e30435
...
...
@@ -140,7 +140,7 @@ class TimerManager {
manual_time_used_
(
0
),
num_finalized_
(
0
),
phase_number_
(
0
),
entered_
(
0
)
entered_
(
0
)
{
}
...
...
@@ -277,7 +277,7 @@ class TimerManager {
int
phase_number_cp
=
phase_number_
;
auto
cb
=
[
this
,
phase_number_cp
]()
{
return
this
->
phase_number_
>
phase_number_cp
||
entered_
==
running_threads_
;
// A thread has aborted in error
entered_
==
running_threads_
;
// A thread has aborted in error
};
phase_condition_
.
wait
(
ml
.
native_handle
(),
cb
);
if
(
phase_number_
>
phase_number_cp
)
...
...
@@ -731,7 +731,7 @@ void FunctionBenchmark::Run(State& st) {
}
// end namespace internal
namespace
{
// Execute one thread of benchmark b for the specified number of iterations.
// Adds the stats collected for the thread into *total.
void
RunInThread
(
const
benchmark
::
internal
::
Benchmark
::
Instance
*
b
,
...
...
@@ -745,15 +745,15 @@ void RunInThread(const benchmark::internal::Benchmark::Instance* b,
MutexLock
l
(
GetBenchmarkLock
());
total
->
bytes_processed
+=
st
.
bytes_processed
();
total
->
items_processed
+=
st
.
items_processed
();
total
->
complexity_n
+=
st
.
complexity_length_n
();
total
->
complexity_n
+=
st
.
complexity_length_n
();
}
timer_manager
->
Finalize
();
}
void
RunBenchmark
(
const
benchmark
::
internal
::
Benchmark
::
Instance
&
b
,
BenchmarkReporter
*
br
,
std
::
vector
<
BenchmarkReporter
::
Run
>&
complexity_reports
)
BenchmarkReporter
*
br
,
std
::
vector
<
BenchmarkReporter
::
Run
>&
complexity_reports
)
EXCLUDES
(
GetBenchmarkLock
())
{
size_t
iters
=
1
;
...
...
@@ -764,7 +764,7 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
pool
.
resize
(
b
.
threads
);
const
int
repeats
=
b
.
repetitions
!=
0
?
b
.
repetitions
:
FLAGS_benchmark_repetitions
;
:
FLAGS_benchmark_repetitions
;
for
(
int
i
=
0
;
i
<
repeats
;
i
++
)
{
std
::
string
mem
;
for
(;;)
{
...
...
@@ -844,28 +844,28 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
report
.
time_unit
=
b
.
time_unit
;
if
(
!
report
.
error_occurred
)
{
double
bytes_per_second
=
0
;
if
(
total
.
bytes_processed
>
0
&&
seconds
>
0.0
)
{
bytes_per_second
=
(
total
.
bytes_processed
/
seconds
);
}
double
items_per_second
=
0
;
if
(
total
.
items_processed
>
0
&&
seconds
>
0.0
)
{
items_per_second
=
(
total
.
items_processed
/
seconds
);
}
if
(
b
.
use_manual_time
)
{
report
.
real_accumulated_time
=
manual_accumulated_time
;
}
else
{
report
.
real_accumulated_time
=
real_accumulated_time
;
}
report
.
cpu_accumulated_time
=
cpu_accumulated_time
;
report
.
bytes_per_second
=
bytes_per_second
;
report
.
items_per_second
=
items_per_second
;
report
.
complexity_n
=
total
.
complexity_n
;
report
.
complexity
=
b
.
complexity
;
report
.
complexity_lambda
=
b
.
complexity_lambda
;
if
(
report
.
complexity
!=
oNone
)
complexity_reports
.
push_back
(
report
);
double
bytes_per_second
=
0
;
if
(
total
.
bytes_processed
>
0
&&
seconds
>
0.0
)
{
bytes_per_second
=
(
total
.
bytes_processed
/
seconds
);
}
double
items_per_second
=
0
;
if
(
total
.
items_processed
>
0
&&
seconds
>
0.0
)
{
items_per_second
=
(
total
.
items_processed
/
seconds
);
}
if
(
b
.
use_manual_time
)
{
report
.
real_accumulated_time
=
manual_accumulated_time
;
}
else
{
report
.
real_accumulated_time
=
real_accumulated_time
;
}
report
.
cpu_accumulated_time
=
cpu_accumulated_time
;
report
.
bytes_per_second
=
bytes_per_second
;
report
.
items_per_second
=
items_per_second
;
report
.
complexity_n
=
total
.
complexity_n
;
report
.
complexity
=
b
.
complexity
;
report
.
complexity_lambda
=
b
.
complexity_lambda
;
if
(
report
.
complexity
!=
oNone
)
complexity_reports
.
push_back
(
report
);
}
reports
.
push_back
(
report
);
...
...
@@ -893,17 +893,17 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
}
std
::
vector
<
BenchmarkReporter
::
Run
>
additional_run_stats
=
ComputeStats
(
reports
);
reports
.
insert
(
reports
.
end
(),
additional_run_stats
.
begin
(),
additional_run_stats
.
end
());
additional_run_stats
.
end
());
if
((
b
.
complexity
!=
oNone
)
&&
b
.
last_benchmark_instance
)
{
additional_run_stats
=
ComputeBigO
(
complexity_reports
);
reports
.
insert
(
reports
.
end
(),
additional_run_stats
.
begin
(),
additional_run_stats
.
end
());
additional_run_stats
.
end
());
complexity_reports
.
clear
();
}
br
->
ReportRuns
(
reports
);
if
(
b
.
multithreaded
)
{
for
(
std
::
thread
&
thread
:
pool
)
thread
.
join
();
...
...
@@ -964,56 +964,56 @@ void State::SetLabel(const char* label) {
}
namespace
internal
{
namespace
{
void
RunMatchingBenchmarks
(
const
std
::
vector
<
Benchmark
::
Instance
>&
benchmarks
,
BenchmarkReporter
*
reporter
)
{
CHECK
(
reporter
!=
nullptr
);
// Determine the width of the name field using a minimum width of 10.
bool
has_repetitions
=
FLAGS_benchmark_repetitions
>
1
;
size_t
name_field_width
=
10
;
for
(
const
Benchmark
::
Instance
&
benchmark
:
benchmarks
)
{
name_field_width
=
std
::
max
<
size_t
>
(
name_field_width
,
benchmark
.
name
.
size
());
has_repetitions
|=
benchmark
.
repetitions
>
1
;
}
if
(
has_repetitions
)
name_field_width
+=
std
::
strlen
(
"_stddev"
);
namespace
{
// Print header here
BenchmarkReporter
::
Context
context
;
context
.
num_cpus
=
NumCPUs
();
context
.
mhz_per_cpu
=
CyclesPerSecond
()
/
1000000.0
f
;
void
RunMatchingBenchmarks
(
const
std
::
vector
<
Benchmark
::
Instance
>&
benchmarks
,
BenchmarkReporter
*
reporter
)
{
CHECK
(
reporter
!=
nullptr
);
// Determine the width of the name field using a minimum width of 10.
bool
has_repetitions
=
FLAGS_benchmark_repetitions
>
1
;
size_t
name_field_width
=
10
;
for
(
const
Benchmark
::
Instance
&
benchmark
:
benchmarks
)
{
name_field_width
=
std
::
max
<
size_t
>
(
name_field_width
,
benchmark
.
name
.
size
());
has_repetitions
|=
benchmark
.
repetitions
>
1
;
}
if
(
has_repetitions
)
name_field_width
+=
std
::
strlen
(
"_stddev"
);
context
.
cpu_scaling_enabled
=
CpuScalingEnabled
();
context
.
name_field_width
=
name_field_width
;
// Print header here
BenchmarkReporter
::
Context
context
;
context
.
num_cpus
=
NumCPUs
();
context
.
mhz_per_cpu
=
CyclesPerSecond
()
/
1000000.0
f
;
// Keep track of runing times of all instances of current benchmark
std
::
vector
<
BenchmarkReporter
::
Run
>
complexity_reports
;
context
.
cpu_scaling_enabled
=
CpuScalingEnabled
();
context
.
name_field_width
=
name_field_width
;
if
(
reporter
->
ReportContext
(
context
))
{
for
(
const
auto
&
benchmark
:
benchmarks
)
{
RunBenchmark
(
benchmark
,
reporter
,
complexity_reports
);
}
}
}
// Keep track of runing times of all instances of current benchmark
std
::
vector
<
BenchmarkReporter
::
Run
>
complexity_reports
;
std
::
unique_ptr
<
BenchmarkReporter
>
GetDefaultReporter
()
{
typedef
std
::
unique_ptr
<
BenchmarkReporter
>
PtrType
;
if
(
FLAGS_benchmark_format
==
"console"
)
{
return
PtrType
(
new
ConsoleReporter
);
}
else
if
(
FLAGS_benchmark_format
==
"json"
)
{
return
PtrType
(
new
JSONReporter
);
}
else
if
(
FLAGS_benchmark_format
==
"csv"
)
{
return
PtrType
(
new
CSVReporter
);
}
else
{
std
::
cerr
<<
"Unexpected format: '"
<<
FLAGS_benchmark_format
<<
"'
\n
"
;
std
::
exit
(
1
);
}
if
(
reporter
->
ReportContext
(
context
))
{
for
(
const
auto
&
benchmark
:
benchmarks
)
{
RunBenchmark
(
benchmark
,
reporter
,
complexity_reports
);
}
}
}
}
// end namespace
std
::
unique_ptr
<
BenchmarkReporter
>
GetDefaultReporter
()
{
typedef
std
::
unique_ptr
<
BenchmarkReporter
>
PtrType
;
if
(
FLAGS_benchmark_format
==
"console"
)
{
return
PtrType
(
new
ConsoleReporter
);
}
else
if
(
FLAGS_benchmark_format
==
"json"
)
{
return
PtrType
(
new
JSONReporter
);
}
else
if
(
FLAGS_benchmark_format
==
"csv"
)
{
return
PtrType
(
new
CSVReporter
);
}
else
{
std
::
cerr
<<
"Unexpected format: '"
<<
FLAGS_benchmark_format
<<
"'
\n
"
;
std
::
exit
(
1
);
}
}
}
// end namespace
}
// end namespace internal
size_t
RunSpecifiedBenchmarks
()
{
...
...
src/complexity.cc
View file @
11e30435
...
...
@@ -194,9 +194,9 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
mean_data
.
benchmark_name
=
reports
[
0
].
benchmark_name
+
"_mean"
;
mean_data
.
iterations
=
run_iterations
;
mean_data
.
real_accumulated_time
=
real_accumulated_time_stat
.
Mean
()
*
run_iterations
;
run_iterations
;
mean_data
.
cpu_accumulated_time
=
cpu_accumulated_time_stat
.
Mean
()
*
run_iterations
;
run_iterations
;
mean_data
.
bytes_per_second
=
bytes_per_second_stat
.
Mean
();
mean_data
.
items_per_second
=
items_per_second_stat
.
Mean
();
...
...
src/complexity.h
View file @
11e30435
...
...
@@ -26,15 +26,15 @@
namespace
benchmark
{
// Return a vector containing the mean and standard devation information for
// the specified list of reports. If 'reports' contains less than two
// non-errored runs an empty vector is returned
std
::
vector
<
BenchmarkReporter
::
Run
>
ComputeStats
(
// Return a vector containing the mean and standard devation information for
// the specified list of reports. If 'reports' contains less than two
// non-errored runs an empty vector is returned
std
::
vector
<
BenchmarkReporter
::
Run
>
ComputeStats
(
const
std
::
vector
<
BenchmarkReporter
::
Run
>&
reports
);
// Return a vector containing the bigO and RMS information for the specified
// list of reports. If 'reports.size() < 2' an empty vector is returned.
std
::
vector
<
BenchmarkReporter
::
Run
>
ComputeBigO
(
// Return a vector containing the bigO and RMS information for the specified
// list of reports. If 'reports.size() < 2' an empty vector is returned.
std
::
vector
<
BenchmarkReporter
::
Run
>
ComputeBigO
(
const
std
::
vector
<
BenchmarkReporter
::
Run
>&
reports
);
// This data structure will contain the result returned by MinimalLeastSq
...
...
src/json_reporter.cc
View file @
11e30435
...
...
@@ -155,7 +155,7 @@ void JSONReporter::PrintRunData(Run const& run) {
}
else
if
(
run
.
report_rms
)
{
out
<<
indent
<<
FormatKV
(
"rms"
,
RoundDouble
(
run
.
GetAdjustedCPUTime
()
*
100
))
<<
"%"
;
<<
'%'
;
}
if
(
run
.
bytes_per_second
>
0.0
)
{
out
<<
",
\n
"
<<
indent
...
...
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