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
0b4111c3
Commit
0b4111c3
authored
Mar 28, 2016
by
Kai Wolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor GetTimeUnitAndMultiplier and add example
parent
7c69b360
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
19 deletions
+32
-19
README.md
README.md
+8
-0
benchmark_api.h
include/benchmark/benchmark_api.h
+7
-0
reporter.h
include/benchmark/reporter.h
+4
-6
console_reporter.cc
src/console_reporter.cc
+1
-13
reporter.cc
src/reporter.cc
+12
-0
No files found.
README.md
View file @
0b4111c3
...
@@ -190,6 +190,14 @@ static void BM_test(benchmark::State& state) {
...
@@ -190,6 +190,14 @@ static void BM_test(benchmark::State& state) {
}
}
```
```
If a benchmark runs a few milliseconds it may be hard to visually compare the
measured times, since the output data is given in nanoseconds per default. In
order to manually set the time unit, you can specify it manually:
```
c++
BENCHMARK
(
BM_test
)
->
Unit
(
benchmark
::
kMillisecond
);
```
Benchmark Fixtures
Benchmark Fixtures
------------------
------------------
Fixture tests are created by
Fixture tests are created by
...
...
include/benchmark/benchmark_api.h
View file @
0b4111c3
...
@@ -137,6 +137,13 @@ static void BM_MultiThreaded(benchmark::State& state) {
...
@@ -137,6 +137,13 @@ static void BM_MultiThreaded(benchmark::State& state) {
}
}
}
}
BENCHMARK(BM_MultiThreaded)->Threads(4);
BENCHMARK(BM_MultiThreaded)->Threads(4);
If a benchmark runs a few milliseconds it may be hard to visually compare the
measured times, since the output data is given in nanoseconds per default. In
order to manually set the time unit, you can specify it manually:
BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
*/
*/
#ifndef BENCHMARK_BENCHMARK_API_H_
#ifndef BENCHMARK_BENCHMARK_API_H_
...
...
include/benchmark/reporter.h
View file @
0b4111c3
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
namespace
benchmark
{
namespace
benchmark
{
typedef
std
::
pair
<
const
char
*
,
double
>
TimeUnitMultiplier
;
// Interface for custom benchmark result printers.
// Interface for custom benchmark result printers.
// By default, benchmark reports are printed to stdout. However an application
// By default, benchmark reports are printed to stdout. However an application
// can control the destination of the reports by calling
// can control the destination of the reports by calling
...
@@ -83,11 +85,10 @@ class BenchmarkReporter {
...
@@ -83,11 +85,10 @@ class BenchmarkReporter {
virtual
~
BenchmarkReporter
();
virtual
~
BenchmarkReporter
();
protected
:
protected
:
static
void
ComputeStats
(
std
::
vector
<
Run
>
const
&
reports
,
Run
*
mean
,
Run
*
stddev
);
static
void
ComputeStats
(
std
::
vector
<
Run
>
const
&
reports
,
Run
*
mean
,
Run
*
stddev
);
static
TimeUnitMultiplier
GetTimeUnitAndMultiplier
(
TimeUnit
unit
);
};
};
typedef
std
::
pair
<
const
char
*
,
double
>
TimeUnitMultiplier
;
// 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
{
...
@@ -98,9 +99,6 @@ class ConsoleReporter : public BenchmarkReporter {
...
@@ -98,9 +99,6 @@ class ConsoleReporter : public BenchmarkReporter {
protected
:
protected
:
virtual
void
PrintRunData
(
const
Run
&
report
);
virtual
void
PrintRunData
(
const
Run
&
report
);
private
:
TimeUnitMultiplier
getTimeUnitAndMultiplier
(
TimeUnit
unit
);
size_t
name_field_width_
;
size_t
name_field_width_
;
};
};
...
...
src/console_reporter.cc
View file @
0b4111c3
...
@@ -95,7 +95,7 @@ void ConsoleReporter::PrintRunData(const Run& result) {
...
@@ -95,7 +95,7 @@ void ConsoleReporter::PrintRunData(const Run& result) {
double
multiplier
;
double
multiplier
;
const
char
*
timeLabel
;
const
char
*
timeLabel
;
std
::
tie
(
timeLabel
,
multiplier
)
=
g
etTimeUnitAndMultiplier
(
result
.
time_unit
);
std
::
tie
(
timeLabel
,
multiplier
)
=
G
etTimeUnitAndMultiplier
(
result
.
time_unit
);
ColorPrintf
(
COLOR_GREEN
,
"%-*s "
,
ColorPrintf
(
COLOR_GREEN
,
"%-*s "
,
name_field_width_
,
result
.
benchmark_name
.
c_str
());
name_field_width_
,
result
.
benchmark_name
.
c_str
());
...
@@ -121,16 +121,4 @@ void ConsoleReporter::PrintRunData(const Run& result) {
...
@@ -121,16 +121,4 @@ void ConsoleReporter::PrintRunData(const Run& result) {
result
.
report_label
.
c_str
());
result
.
report_label
.
c_str
());
}
}
TimeUnitMultiplier
ConsoleReporter
::
getTimeUnitAndMultiplier
(
TimeUnit
unit
)
{
switch
(
unit
)
{
case
kMillisecond
:
return
std
::
make_pair
(
"ms"
,
1e3
);
case
kMicrosecond
:
return
std
::
make_pair
(
"us"
,
1e6
);
case
kNanosecond
:
default
:
return
std
::
make_pair
(
"ns"
,
1e9
);
}
}
}
// end namespace benchmark
}
// end namespace benchmark
src/reporter.cc
View file @
0b4111c3
...
@@ -77,6 +77,18 @@ void BenchmarkReporter::ComputeStats(
...
@@ -77,6 +77,18 @@ void BenchmarkReporter::ComputeStats(
stddev_data
->
items_per_second
=
items_per_second_stat
.
StdDev
();
stddev_data
->
items_per_second
=
items_per_second_stat
.
StdDev
();
}
}
TimeUnitMultiplier
BenchmarkReporter
::
GetTimeUnitAndMultiplier
(
TimeUnit
unit
)
{
switch
(
unit
)
{
case
kMillisecond
:
return
std
::
make_pair
(
"ms"
,
1e3
);
case
kMicrosecond
:
return
std
::
make_pair
(
"us"
,
1e6
);
case
kNanosecond
:
default
:
return
std
::
make_pair
(
"ns"
,
1e9
);
}
}
void
BenchmarkReporter
::
Finalize
()
{
void
BenchmarkReporter
::
Finalize
()
{
}
}
...
...
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