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
1ce286f6
Commit
1ce286f6
authored
Apr 29, 2017
by
Joao Paulo Magalhaes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid compiler-specific pragmas in result check macros.
- Epsilon is now understood as relative to expected value. - Improve error messages for epsilon checks.
parent
da69e5de
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
45 deletions
+55
-45
output_test.h
test/output_test.h
+44
-34
user_counters_test.cc
test/user_counters_test.cc
+11
-11
No files found.
test/output_test.h
View file @
1ce286f6
...
@@ -148,40 +148,50 @@ struct ResultsCheckerEntry {
...
@@ -148,40 +148,50 @@ struct ResultsCheckerEntry {
// checked.
// checked.
size_t
AddChecker
(
const
char
*
bm_name
,
ResultsCheckFn
fn
);
size_t
AddChecker
(
const
char
*
bm_name
,
ResultsCheckFn
fn
);
#ifdef __clang__
//----------------------------------
/* NOTE: using , ## __VA_ARGS__ to deal with zero-args calls to
// Macros to help in result checking. Do not use them with arguments causing
* variadic macros is not portable, but works in clang, gcc, msvc, icc.
// side-effects.
* clang requires switching off compiler warnings for pedantic mode.
* @see http://stackoverflow.com/questions/32047685/variadic-macro-without-arguments */
#define _CHECK_RESULT_VALUE(entry, getfn, var_type, var_name, relationship, value) \
# pragma clang diagnostic push
CONCAT(CHECK_, relationship) \
// warning: token pasting of ',' and __VA_ARGS__ is a GNU extension
(entry.getfn< var_type >(var_name), (value)) << "\n" \
# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
<< __FILE__ << ":" << __LINE__ << ": " << (entry).name << ":\n" \
#elif defined(__GNUC__)
<< __FILE__ << ":" << __LINE__ << ": " \
/* GCC also issues a warning for zero-args calls to variadic macros.
<< "expected (" << #var_type << ")" << (var_name) \
* This warning is switched on with -pedantic and apparently there is no
<< "=" << (entry).getfn< var_type >(var_name) \
* easy way to turn it off as with clang. But marking this as a system
<< " to be " #relationship " to " << (value) << "\n"
* header works.
* @see https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html
// check with tolerance. eps_factor is the tolerance window, which will be
* @see http://stackoverflow.com/questions/35587137/ */
// interpreted relative to value.
# pragma GCC system_header
#define _CHECK_RESULT_VALUE_EPS(entry, getfn, var_type, var_name, relationship, value, eps_factor) \
#endif
CONCAT(CHECK_, relationship) \
(entry.getfn< var_type >(var_name), (value), (eps_factor) * (value)) << "\n" \
#define _CHECK_RESULT_VALUE(entry, getfn, var_type, var_name, relationship, value, ...) \
<< __FILE__ << ":" << __LINE__ << ": " << (entry).name << ":\n" \
CONCAT(CHECK_, relationship)(entry.getfn< var_type >(var_name), (value), ## __VA_ARGS__) \
<< __FILE__ << ":" << __LINE__ << ": " \
<< "\n" << __FILE__ << ":" << __LINE__ << ": " \
<< "expected (" << #var_type << ")" << (var_name) \
<< entry.name << ": expected (" << #var_type << ")" \
<< "=" << (entry).getfn< var_type >(var_name) \
<< var_name << "=" << entry.getfn< var_type >(var_name) \
<< " to be " #relationship " to " << (value) << "\n" \
<< " to be " #relationship " to " << (value);
<< __FILE__ << ":" << __LINE__ << ": " \
<< "with tolerance of " << (eps_factor) * (value) \
#define CHECK_RESULT_VALUE(entry, var_type, var_name, relationship, value, ...) \
<< " (" << (eps_factor)*100. << "%), " \
_CHECK_RESULT_VALUE(entry, GetAs, var_type, var_name, relationship, value, ## __VA_ARGS__)
<< "but delta was " << ((entry).getfn< var_type >(var_name) - (value)) \
<< " (" << (((entry).getfn< var_type >(var_name) - (value)) \
#define CHECK_COUNTER_VALUE(entry, var_type, var_name, relationship, value, ...) \
/ \
_CHECK_RESULT_VALUE(entry, GetCounterAs, var_type, var_name, relationship, value, ## __VA_ARGS__)
((value) > 1.e-5 || value < -1.e-5 ? value : 1.e-5)*100.) \
<< "%)"
#ifdef __clang__
# pragma clang diagnostic pop
#define CHECK_RESULT_VALUE(entry, var_type, var_name, relationship, value) \
#endif
_CHECK_RESULT_VALUE(entry, GetAs, var_type, var_name, relationship, value)
#define CHECK_COUNTER_VALUE(entry, var_type, var_name, relationship, value) \
_CHECK_RESULT_VALUE(entry, GetCounterAs, var_type, var_name, relationship, value)
#define CHECK_RESULT_VALUE_EPS(entry, var_name, relationship, value, eps_factor) \
_CHECK_RESULT_VALUE_EPS(entry, GetAs, double, var_name, relationship, value, eps_factor)
#define CHECK_COUNTER_VALUE_EPS(entry, var_name, relationship, value, eps_factor) \
_CHECK_RESULT_VALUE_EPS(entry, GetCounterAs, double, var_name, relationship, value, eps_factor)
#define CHECK_BENCHMARK_RESULTS(bm_name, checker_function) \
#define CHECK_BENCHMARK_RESULTS(bm_name, checker_function) \
size_t CONCAT(dummy, __LINE__) = AddChecker(bm_name, checker_function)
size_t CONCAT(dummy, __LINE__) = AddChecker(bm_name, checker_function)
...
...
test/user_counters_test.cc
View file @
1ce286f6
...
@@ -24,7 +24,7 @@ void BM_Counters_Simple(benchmark::State& state) {
...
@@ -24,7 +24,7 @@ void BM_Counters_Simple(benchmark::State& state) {
state
.
counters
[
"foo"
]
=
1
;
state
.
counters
[
"foo"
]
=
1
;
state
.
counters
[
"bar"
]
=
2
*
state
.
iterations
();
state
.
counters
[
"bar"
]
=
2
*
state
.
iterations
();
}
}
BENCHMARK
(
BM_Counters_Simple
);
//->ThreadRange(1, 32);
BENCHMARK
(
BM_Counters_Simple
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_Counters_Simple %console_report bar=%hrfloat foo=%hrfloat$"
}});
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_Counters_Simple %console_report bar=%hrfloat foo=%hrfloat$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_Counters_Simple
\"
,$"
},
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_Counters_Simple
\"
,$"
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
...
@@ -39,7 +39,7 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_Simple", [](ResultsCheckerEntry const& e) {
...
@@ -39,7 +39,7 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_Simple", [](ResultsCheckerEntry const& e) {
double
its
=
e
.
GetAs
<
double
>
(
"iterations"
);
double
its
=
e
.
GetAs
<
double
>
(
"iterations"
);
CHECK_COUNTER_VALUE
(
e
,
int
,
"foo"
,
EQ
,
1
);
CHECK_COUNTER_VALUE
(
e
,
int
,
"foo"
,
EQ
,
1
);
// check that the value of bar is within 0.1% of the expected value
// check that the value of bar is within 0.1% of the expected value
CHECK_COUNTER_VALUE
(
e
,
double
,
"bar"
,
EQ_EPS
,
2.
*
its
,
0.001
*
its
);
CHECK_COUNTER_VALUE
_EPS
(
e
,
"bar"
,
EQ_EPS
,
2.
*
its
,
0.001
);
});
});
// ========================================================================= //
// ========================================================================= //
...
@@ -55,10 +55,10 @@ void BM_Counters_WithBytesAndItemsPSec(benchmark::State& state) {
...
@@ -55,10 +55,10 @@ void BM_Counters_WithBytesAndItemsPSec(benchmark::State& state) {
state
.
SetBytesProcessed
(
364
);
state
.
SetBytesProcessed
(
364
);
state
.
SetItemsProcessed
(
150
);
state
.
SetItemsProcessed
(
150
);
}
}
BENCHMARK
(
BM_Counters_WithBytesAndItemsPSec
);
//->ThreadRange(1, 32);
BENCHMARK
(
BM_Counters_WithBytesAndItemsPSec
);
ADD_CASES
(
TC_ConsoleOut
,
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_Counters_WithBytesAndItemsPSec %console_report "
{{
"^BM_Counters_WithBytesAndItemsPSec %console_report "
"bar=%hrfloat foo=%hrfloat +%
floatB/s +%
float items/s$"
}});
"bar=%hrfloat foo=%hrfloat +%
hrfloatB/s +%hr
float items/s$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_Counters_WithBytesAndItemsPSec
\"
,$"
},
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_Counters_WithBytesAndItemsPSec
\"
,$"
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
real_time
\"
: %int,$"
,
MR_Next
},
{
"
\"
real_time
\"
: %int,$"
,
MR_Next
},
...
@@ -73,12 +73,12 @@ ADD_CASES(TC_CSVOut, {{"^\"BM_Counters_WithBytesAndItemsPSec\","
...
@@ -73,12 +73,12 @@ ADD_CASES(TC_CSVOut, {{"^\"BM_Counters_WithBytesAndItemsPSec\","
"%csv_bytes_items_report,%float,%float$"
}});
"%csv_bytes_items_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_WithBytesAndItemsPSec"
,
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_WithBytesAndItemsPSec"
,
[](
ResultsCheckerEntry
const
&
e
)
{
[](
ResultsCheckerEntry
const
&
e
)
{
double
t
=
e
.
DurationCPUTime
();
// this (and not real time) is the time used
CHECK_COUNTER_VALUE
(
e
,
int
,
"foo"
,
EQ
,
1
);
CHECK_COUNTER_VALUE
(
e
,
int
,
"foo"
,
EQ
,
1
);
CHECK_COUNTER_VALUE
(
e
,
int
,
"bar"
,
EQ
,
num_calls1
);
CHECK_COUNTER_VALUE
(
e
,
int
,
"bar"
,
EQ
,
num_calls1
);
// check that the values are within 0.1% of the expected values
// check that the values are within 0.1% of the expected values
double
t
=
e
.
DurationCPUTime
();
// this (and not real time) is the time used
CHECK_RESULT_VALUE_EPS
(
e
,
"bytes_per_second"
,
EQ_EPS
,
364.
/
t
,
0.001
);
CHECK_RESULT_VALUE
(
e
,
double
,
"bytes_per_second"
,
EQ_EPS
,
364.
/
t
,
0.001
*
t
);
CHECK_RESULT_VALUE_EPS
(
e
,
"items_per_second"
,
EQ_EPS
,
150.
/
t
,
0.001
);
CHECK_RESULT_VALUE
(
e
,
double
,
"items_per_second"
,
EQ_EPS
,
150.
/
t
,
0.001
*
t
);
});
});
// ========================================================================= //
// ========================================================================= //
...
@@ -92,7 +92,7 @@ void BM_Counters_Rate(benchmark::State& state) {
...
@@ -92,7 +92,7 @@ void BM_Counters_Rate(benchmark::State& state) {
state
.
counters
[
"foo"
]
=
bm
::
Counter
{
1
,
bm
::
Counter
::
kIsRate
};
state
.
counters
[
"foo"
]
=
bm
::
Counter
{
1
,
bm
::
Counter
::
kIsRate
};
state
.
counters
[
"bar"
]
=
bm
::
Counter
{
2
,
bm
::
Counter
::
kIsRate
};
state
.
counters
[
"bar"
]
=
bm
::
Counter
{
2
,
bm
::
Counter
::
kIsRate
};
}
}
BENCHMARK
(
BM_Counters_Rate
);
//->ThreadRange(1, 32);
BENCHMARK
(
BM_Counters_Rate
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_Counters_Rate %console_report bar=%hrfloat foo=%hrfloat$"
}});
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_Counters_Rate %console_report bar=%hrfloat foo=%hrfloat$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_Counters_Rate
\"
,$"
},
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_Counters_Rate
\"
,$"
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
...
@@ -105,10 +105,10 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_Rate\",$"},
...
@@ -105,10 +105,10 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_Rate\",$"},
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_Rate
\"
,%csv_report,%float,%float$"
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_Rate
\"
,%csv_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_Rate"
,
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_Rate"
,
[](
ResultsCheckerEntry
const
&
e
)
{
[](
ResultsCheckerEntry
const
&
e
)
{
// check that the values are within 0.1% of the expected values
double
t
=
e
.
DurationCPUTime
();
// this (and not real time) is the time used
double
t
=
e
.
DurationCPUTime
();
// this (and not real time) is the time used
CHECK_COUNTER_VALUE
(
e
,
double
,
"foo"
,
EQ_EPS
,
5.
/
t
,
0.001
*
t
);
// check that the values are within 0.1% of the expected values
CHECK_COUNTER_VALUE
(
e
,
double
,
"bar"
,
EQ_EPS
,
2.
/
t
,
0.001
*
t
);
CHECK_COUNTER_VALUE_EPS
(
e
,
"foo"
,
EQ_EPS
,
1.
/
t
,
0.001
);
CHECK_COUNTER_VALUE_EPS
(
e
,
"bar"
,
EQ_EPS
,
2.
/
t
,
0.001
);
});
});
// ========================================================================= //
// ========================================================================= //
...
...
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