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
36a9ae19
Commit
36a9ae19
authored
May 24, 2016
by
Ismael
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added SetComplexityN
parent
855786ac
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
10 deletions
+31
-10
benchmark_api.h
include/benchmark/benchmark_api.h
+16
-1
reporter.h
include/benchmark/reporter.h
+2
-4
benchmark.cc
src/benchmark.cc
+6
-4
reporter.cc
src/reporter.cc
+1
-1
complexity_test.cc
test/complexity_test.cc
+6
-0
No files found.
include/benchmark/benchmark_api.h
View file @
36a9ae19
...
...
@@ -312,6 +312,19 @@ public:
return
bytes_processed_
;
}
// If this routine is called with complexity_n > 0 and complexity report is requested for the
// family benchmark, then current benchmark will be part of the computation and complexity_n will
// represent the length of N.
BENCHMARK_ALWAYS_INLINE
void
SetComplexityN
(
size_t
complexity_n
)
{
complexity_n_
=
complexity_n
;
}
BENCHMARK_ALWAYS_INLINE
size_t
complexity_n
()
{
return
complexity_n_
;
}
// If this routine is called with items > 0, then an items/s
// label is printed on the benchmark report line for the currently
// executing benchmark. It is typically called at the end of a processing
...
...
@@ -383,6 +396,8 @@ private:
size_t
bytes_processed_
;
size_t
items_processed_
;
size_t
complexity_n_
;
public
:
// Index of the executing thread. Values from [0, threads).
const
int
thread_index
;
...
...
@@ -466,7 +481,7 @@ 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
);
...
...
include/benchmark/reporter.h
View file @
36a9ae19
...
...
@@ -50,8 +50,7 @@ class BenchmarkReporter {
items_per_second
(
0
),
max_heapbytes_used
(
0
),
complexity
(
oNone
),
arg1
(
0
),
arg2
(
0
),
complexity_n
(
0
),
report_big_o
(
false
),
report_rms
(
false
)
{}
...
...
@@ -71,8 +70,7 @@ class BenchmarkReporter {
// Keep track of arguments to compute asymptotic complexity
BigO
complexity
;
int
arg1
;
int
arg2
;
int
complexity_n
;
// Inform print function whether the current run is a complexity report
bool
report_big_o
;
...
...
src/benchmark.cc
View file @
36a9ae19
...
...
@@ -116,9 +116,10 @@ std::string* GetReportLabel() {
//static benchmark::MallocCounter *benchmark_mc;
struct
ThreadStats
{
ThreadStats
()
:
bytes_processed
(
0
),
items_processed
(
0
)
{}
ThreadStats
()
:
bytes_processed
(
0
),
items_processed
(
0
)
,
complexity_n
(
0
)
{}
int64_t
bytes_processed
;
int64_t
items_processed
;
size_t
complexity_n
;
};
// Timer management class
...
...
@@ -693,6 +694,7 @@ 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_n
();
}
timer_manager
->
Finalize
();
...
...
@@ -798,8 +800,7 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
report
.
cpu_accumulated_time
=
cpu_accumulated_time
;
report
.
bytes_per_second
=
bytes_per_second
;
report
.
items_per_second
=
items_per_second
;
report
.
arg1
=
b
.
arg1
;
report
.
arg2
=
b
.
arg2
;
report
.
complexity_n
=
total
.
complexity_n
;
report
.
complexity
=
b
.
complexity
;
reports
.
push_back
(
report
);
...
...
@@ -851,7 +852,8 @@ State::State(size_t max_iters, bool has_x, int x, bool has_y, int y,
bytes_processed_
(
0
),
items_processed_
(
0
),
thread_index
(
thread_i
),
threads
(
n_threads
),
max_iterations
(
max_iters
)
max_iterations
(
max_iters
),
complexity_n_
(
0
)
{
CHECK
(
max_iterations
!=
0
)
<<
"At least one iteration must be run"
;
CHECK_LT
(
thread_index
,
threads
)
<<
"thread_index must be less than threads"
;
...
...
src/reporter.cc
View file @
36a9ae19
...
...
@@ -90,7 +90,7 @@ void BenchmarkReporter::ComputeBigO(
// Populate the accumulators.
for
(
const
Run
&
run
:
reports
)
{
n
.
push_back
(
run
.
arg1
);
n
.
push_back
(
run
.
complexity_n
);
real_time
.
push_back
(
run
.
real_accumulated_time
/
run
.
iterations
);
cpu_time
.
push_back
(
run
.
cpu_accumulated_time
/
run
.
iterations
);
}
...
...
test/complexity_test.cc
View file @
36a9ae19
...
...
@@ -26,6 +26,7 @@ std::map<int, int> ConstructRandomMap(int size) {
void
BM_Complexity_O1
(
benchmark
::
State
&
state
)
{
while
(
state
.
KeepRunning
())
{
}
state
.
SetComplexityN
(
state
.
range_x
());
}
BENCHMARK
(
BM_Complexity_O1
)
->
Range
(
1
,
1
<<
18
)
->
Complexity
(
benchmark
::
o1
);
...
...
@@ -35,6 +36,7 @@ static void BM_Complexity_O_N(benchmark::State& state) {
while
(
state
.
KeepRunning
())
{
benchmark
::
DoNotOptimize
(
std
::
find
(
v
.
begin
(),
v
.
end
(),
item_not_in_vector
));
}
state
.
SetComplexityN
(
state
.
range_x
());
}
BENCHMARK
(
BM_Complexity_O_N
)
->
RangeMultiplier
(
2
)
->
Range
(
1
<<
10
,
1
<<
16
)
->
Complexity
(
benchmark
::
oN
);
BENCHMARK
(
BM_Complexity_O_N
)
->
RangeMultiplier
(
2
)
->
Range
(
1
<<
10
,
1
<<
16
)
->
Complexity
(
benchmark
::
oAuto
);
...
...
@@ -42,6 +44,7 @@ BENCHMARK(BM_Complexity_O_N) -> RangeMultiplier(2) -> Range(1<<10, 1<<16) -> Com
static
void
BM_Complexity_O_N_Squared
(
benchmark
::
State
&
state
)
{
std
::
string
s1
(
state
.
range_x
(),
'-'
);
std
::
string
s2
(
state
.
range_x
(),
'-'
);
state
.
SetComplexityN
(
state
.
range_x
());
while
(
state
.
KeepRunning
())
for
(
char
&
c1
:
s1
)
{
for
(
char
&
c2
:
s2
)
{
...
...
@@ -56,6 +59,7 @@ static void BM_Complexity_O_N_Cubed(benchmark::State& state) {
std
::
string
s1
(
state
.
range_x
(),
'-'
);
std
::
string
s2
(
state
.
range_x
(),
'-'
);
std
::
string
s3
(
state
.
range_x
(),
'-'
);
state
.
SetComplexityN
(
state
.
range_x
());
while
(
state
.
KeepRunning
())
for
(
char
&
c1
:
s1
)
{
for
(
char
&
c2
:
s2
)
{
...
...
@@ -75,6 +79,7 @@ static void BM_Complexity_O_log_N(benchmark::State& state) {
while
(
state
.
KeepRunning
())
{
benchmark
::
DoNotOptimize
(
m
.
find
(
item_not_in_vector
));
}
state
.
SetComplexityN
(
state
.
range_x
());
}
BENCHMARK
(
BM_Complexity_O_log_N
)
->
RangeMultiplier
(
2
)
->
Range
(
1
<<
10
,
1
<<
16
)
->
Complexity
(
benchmark
::
oLogN
);
...
...
@@ -84,6 +89,7 @@ static void BM_Complexity_O_N_log_N(benchmark::State& state) {
while
(
state
.
KeepRunning
())
{
std
::
sort
(
v
.
begin
(),
v
.
end
());
}
state
.
SetComplexityN
(
state
.
range_x
());
}
BENCHMARK
(
BM_Complexity_O_N_log_N
)
->
RangeMultiplier
(
2
)
->
Range
(
1
<<
10
,
1
<<
16
)
->
Complexity
(
benchmark
::
oNLogN
);
BENCHMARK
(
BM_Complexity_O_N_log_N
)
->
RangeMultiplier
(
2
)
->
Range
(
1
<<
10
,
1
<<
16
)
->
Complexity
(
benchmark
::
oAuto
);
...
...
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