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
180719d0
Commit
180719d0
authored
Apr 29, 2017
by
Joao Paulo Magalhaes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ResultsCheckerEntry to Results.
parent
f3b82a8e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
32 deletions
+39
-32
output_test.h
test/output_test.h
+29
-22
output_test_helper.cc
test/output_test_helper.cc
+4
-4
user_counters_test.cc
test/user_counters_test.cc
+6
-6
No files found.
test/output_test.h
View file @
180719d0
...
...
@@ -62,22 +62,24 @@ void RunOutputTests(int argc, char* argv[]);
// ------------------------- Results checking ------------------------------ //
// ========================================================================= //
struct
Results
CheckerEntry
;
typedef
std
::
function
<
void
(
Results
CheckerEntry
const
&
)
>
ResultsCheckFn
;
struct
Results
;
typedef
std
::
function
<
void
(
Results
const
&
)
>
ResultsCheckFn
;
// Add a function to check the (CSV) results of a benchmark. These
// functions will be called only after the output was successfully
// checked.
size_t
AddChecker
(
const
char
*
bm_name
,
ResultsCheckFn
fn
);
// Class to test the results of a benchmark.
// It inspects the results by looking at the CSV output of a subscribed
// benchmark.
struct
ResultsCheckerEntry
{
std
::
string
name
;
// bm_name_pattern: a name or a regex which will be matched agains
// all the benchmark names. Matching benchmarks
// will be the subject of a call to fn
size_t
AddChecker
(
const
char
*
bm_name_pattern
,
ResultsCheckFn
fn
);
// Class to hold the (CSV!) results of a benchmark.
// It is passed in calls to checker functions.
struct
Results
{
std
::
string
name
;
// the benchmark name
std
::
map
<
std
::
string
,
std
::
string
>
values
;
Results
CheckerEntry
(
const
std
::
string
&
n
)
:
name
(
n
)
{}
Results
(
const
std
::
string
&
n
)
:
name
(
n
)
{}
int
NumThreads
()
const
;
...
...
@@ -99,21 +101,14 @@ struct ResultsCheckerEntry {
}
// get a result by name, parsed as a specific type.
// For counters, use GetCounterAs instead.
template
<
class
T
>
T
GetAs
(
const
char
*
entry_name
)
const
{
auto
*
sv
=
Get
(
entry_name
);
CHECK
(
sv
!=
nullptr
&&
!
sv
->
empty
());
std
::
stringstream
ss
;
ss
<<
*
sv
;
T
out
;
ss
>>
out
;
CHECK
(
!
ss
.
fail
());
return
out
;
}
// NOTE: for counters, use GetCounterAs instead.
template
<
class
T
>
T
GetAs
(
const
char
*
entry_name
)
const
;
// counters are written as doubles, so they have to be read first
// as a double, and only then converted to the asked type.
template
<
class
T
>
T
GetCounterAs
(
const
char
*
entry_name
)
const
{
template
<
class
T
>
T
GetCounterAs
(
const
char
*
entry_name
)
const
{
double
dval
=
GetAs
<
double
>
(
entry_name
);
T
tval
=
static_cast
<
T
>
(
dval
);
return
tval
;
...
...
@@ -123,6 +118,18 @@ struct ResultsCheckerEntry {
double
GetTime
(
const
char
*
which
)
const
;
};
template
<
class
T
>
T
Results
::
GetAs
(
const
char
*
entry_name
)
const
{
auto
*
sv
=
Get
(
entry_name
);
CHECK
(
sv
!=
nullptr
&&
!
sv
->
empty
());
std
::
stringstream
ss
;
ss
<<
*
sv
;
T
out
;
ss
>>
out
;
CHECK
(
!
ss
.
fail
());
return
out
;
}
//----------------------------------
// Macros to help in result checking. Do not use them with arguments causing
// side-effects.
...
...
test/output_test_helper.cc
View file @
180719d0
...
...
@@ -169,7 +169,7 @@ class ResultsChecker {
};
std
::
vector
<
PatternAndFn
>
check_patterns
;
std
::
vector
<
Results
CheckerEntry
>
results
;
std
::
vector
<
Results
>
results
;
std
::
vector
<
std
::
string
>
field_names
;
void
Add
(
const
std
::
string
&
entry_pattern
,
ResultsCheckFn
fn
);
...
...
@@ -178,7 +178,7 @@ class ResultsChecker {
private
:
Results
CheckerEntry
*
Find_
(
const
std
::
string
&
entry_name
);
Results
*
Find_
(
const
std
::
string
&
entry_name
);
void
SetHeader_
(
const
std
::
string
&
csv_header
);
void
SetValues_
(
const
std
::
string
&
entry_csv_line
);
...
...
@@ -293,7 +293,7 @@ size_t AddChecker(const char* bm_name, ResultsCheckFn fn)
return
rc
.
results
.
size
();
}
int
Results
CheckerEntry
::
NumThreads
()
const
{
int
Results
::
NumThreads
()
const
{
auto
pos
=
name
.
find
(
"/threads:"
);
if
(
pos
==
name
.
npos
)
return
1
;
auto
end
=
name
.
find
(
'/'
,
pos
+
9
);
...
...
@@ -305,7 +305,7 @@ int ResultsCheckerEntry::NumThreads() const {
return
num
;
}
double
Results
CheckerEntry
::
GetTime
(
const
char
*
which
)
const
{
double
Results
::
GetTime
(
const
char
*
which
)
const
{
double
val
=
GetAs
<
double
>
(
which
);
auto
unit
=
Get
(
"time_unit"
);
CHECK
(
unit
);
...
...
test/user_counters_test.cc
View file @
180719d0
...
...
@@ -35,7 +35,7 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_Simple\",$"},
{
"
\"
foo
\"
: %float$"
,
MR_Next
},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_Simple
\"
,%csv_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_Simple"
,
[](
Results
CheckerEntry
const
&
e
)
{
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_Simple"
,
[](
Results
const
&
e
)
{
double
its
=
e
.
GetAs
<
double
>
(
"iterations"
);
CHECK_COUNTER_VALUE
(
e
,
int
,
"foo"
,
EQ
,
1
);
// check that the value of bar is within 0.1% of the expected value
...
...
@@ -72,7 +72,7 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_WithBytesAndItemsPSec\",$"},
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_WithBytesAndItemsPSec
\"
,"
"%csv_bytes_items_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_WithBytesAndItemsPSec"
,
[](
Results
CheckerEntry
const
&
e
)
{
[](
Results
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
,
"bar"
,
EQ
,
num_calls1
);
...
...
@@ -104,7 +104,7 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_Rate\",$"},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_Rate
\"
,%csv_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_Rate"
,
[](
Results
CheckerEntry
const
&
e
)
{
[](
Results
const
&
e
)
{
double
t
=
e
.
DurationCPUTime
();
// this (and not real time) is the time used
// check that the values are within 0.1% of the expected values
CHECK_COUNTER_VALUE_EPS
(
e
,
"foo"
,
EQ_EPS
,
1.
/
t
,
0.001
);
...
...
@@ -133,7 +133,7 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_Threads/threads:%int\",$"},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_Threads/threads:%int
\"
,%csv_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_Threads/threads:%int"
,
[](
Results
CheckerEntry
const
&
e
)
{
[](
Results
const
&
e
)
{
CHECK_COUNTER_VALUE
(
e
,
int
,
"foo"
,
EQ
,
e
.
NumThreads
());
CHECK_COUNTER_VALUE
(
e
,
int
,
"bar"
,
EQ
,
2
*
e
.
NumThreads
());
});
...
...
@@ -161,7 +161,7 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_AvgThreads/threads:%int\",$"},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_AvgThreads/threads:%int
\"
,%csv_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_AvgThreads/threads:%int"
,
[](
Results
CheckerEntry
const
&
e
)
{
[](
Results
const
&
e
)
{
CHECK_COUNTER_VALUE
(
e
,
int
,
"foo"
,
EQ
,
1
);
CHECK_COUNTER_VALUE
(
e
,
int
,
"bar"
,
EQ
,
2
);
});
...
...
@@ -189,7 +189,7 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_AvgThreadsRate/threads:%int\",$
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_Counters_AvgThreadsRate/threads:%int
\"
,%csv_report,%float,%float$"
}});
CHECK_BENCHMARK_RESULTS
(
"BM_Counters_AvgThreadsRate/threads:%int"
,
[](
Results
CheckerEntry
const
&
e
)
{
[](
Results
const
&
e
)
{
CHECK_COUNTER_VALUE_EPS
(
e
,
"foo"
,
EQ_EPS
,
1.
/
e
.
DurationCPUTime
(),
0.001
);
CHECK_COUNTER_VALUE_EPS
(
e
,
"bar"
,
EQ_EPS
,
2.
/
e
.
DurationCPUTime
(),
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