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
3b40f0a7
Commit
3b40f0a7
authored
Mar 09, 2015
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filter test, remove re test, and googletest deps
parent
522a5891
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
144 deletions
+98
-144
CMakeLists.txt
test/CMakeLists.txt
+10
-28
benchmark_test.cc
test/benchmark_test.cc
+2
-37
filter_test.cc
test/filter_test.cc
+86
-0
re_test.cc
test/re_test.cc
+0
-79
No files found.
test/CMakeLists.txt
View file @
3b40f0a7
# Enable the tests
# Enable the tests
# Import and build Google Test
include
(
ExternalProject
)
set_directory_properties
(
properties EP_PREFIX
"
${
CMAKE_BINARY_DIR
}
/third_party"
)
ExternalProject_Add
(
googletest
URL
"https://googletest.googlecode.com/files/gtest-1.7.0.zip"
URL_MD5 2d6ec8ccdf5c46b05ba54a9fd1d130d7
SOURCE_DIR
"
${
CMAKE_BINARY_DIR
}
/third_party/gtest"
CMAKE_ARGS
"-DCMAKE_CXX_COMPILER=
${
CMAKE_CXX_COMPILER
}
"
INSTALL_COMMAND
""
)
ExternalProject_Get_Property
(
googletest source_dir
)
ExternalProject_Get_Property
(
googletest binary_dir
)
include_directories
(
${
source_dir
}
/include
)
link_directories
(
${
binary_dir
}
)
find_package
(
Threads REQUIRED
)
find_package
(
Threads REQUIRED
)
macro
(
compile_benchmark_test name
)
macro
(
compile_benchmark_test name
)
add_executable
(
${
name
}
"
${
name
}
.cc"
)
add_executable
(
${
name
}
"
${
name
}
.cc"
)
target_link_libraries
(
${
name
}
benchmark gtest
${
CMAKE_THREAD_LIBS_INIT
}
)
target_link_libraries
(
${
name
}
benchmark
${
CMAKE_THREAD_LIBS_INIT
}
)
add_dependencies
(
${
name
}
googletest
)
endmacro
(
compile_benchmark_test
)
endmacro
(
compile_benchmark_test
)
macro
(
add_gtest_test name
)
add_executable
(
${
name
}
"
${
name
}
.cc"
)
target_link_libraries
(
${
name
}
benchmark gtest gtest_main
${
CMAKE_THREAD_LIBS_INIT
}
)
add_dependencies
(
${
name
}
googletest
)
add_test
(
${
name
}
${
name
}
)
endmacro
(
add_gtest_test
)
# Demonstration executable
# Demonstration executable
compile_benchmark_test
(
benchmark_test
)
compile_benchmark_test
(
benchmark_test
)
add_test
(
benchmark benchmark_test --benchmark_min_time=0.1 51
)
add_test
(
benchmark benchmark_test --benchmark_min_time=0.1 51
)
add_test
(
benchmark_filter_simple benchmark_test --benchmark_filter=Calculate 16
)
add_test
(
benchmark_filter_suffix benchmark_test --benchmark_filter=Calculate* 16
)
add_test
(
benchmark_filter_regex_wildcard benchmark_test --benchmark_filter=.*Calculate.* 16
)
add_gtest_test
(
re_test
)
compile_benchmark_test
(
filter_test
)
add_test
(
filter_simple filter_test --benchmark_filter=Calculate 16
)
add_test
(
filter_suffix filter_test --benchmark_filter=Calculate* 16
)
add_test
(
filter_regex_all filter_test --benchmark_filter=.* 16
)
add_test
(
filter_regex_blank filter_test --benchmark_filter= 16
)
add_test
(
filter_regex_none filter_test --benchmark_filter=monkey 0
)
add_test
(
filter_regex_wildcard filter_test --benchmark_filter=.*Calculate.* 16
)
add_test
(
filter_regex_begin filter_test --benchmark_filter=^BM_Calculate.* 16
)
add_test
(
filter_regex_end filter_test --benchmark_filter=.*Pi$ 8
)
test/benchmark_test.cc
View file @
3b40f0a7
...
@@ -14,8 +14,6 @@
...
@@ -14,8 +14,6 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <gtest/gtest.h>
#if defined(__GNUC__)
#if defined(__GNUC__)
# define BENCHMARK_NOINLINE __attribute__((noinline))
# define BENCHMARK_NOINLINE __attribute__((noinline))
#else
#else
...
@@ -55,7 +53,7 @@ static void BM_Factorial(benchmark::State& state) {
...
@@ -55,7 +53,7 @@ static void BM_Factorial(benchmark::State& state) {
while
(
state
.
KeepRunning
())
while
(
state
.
KeepRunning
())
fac_42
=
Factorial
(
8
);
fac_42
=
Factorial
(
8
);
// Prevent compiler optimizations
// Prevent compiler optimizations
EXPECT_NE
(
fac_42
,
std
::
numeric_limits
<
int
>::
max
())
;
std
::
cout
<<
fac_42
;
}
}
BENCHMARK
(
BM_Factorial
);
BENCHMARK
(
BM_Factorial
);
...
@@ -149,45 +147,12 @@ static void BM_LongTest(benchmark::State& state) {
...
@@ -149,45 +147,12 @@ static void BM_LongTest(benchmark::State& state) {
}
}
BENCHMARK
(
BM_LongTest
)
->
Range
(
1
<<
16
,
1
<<
28
);
BENCHMARK
(
BM_LongTest
)
->
Range
(
1
<<
16
,
1
<<
28
);
class
TestReporter
:
public
benchmark
::
internal
::
ConsoleReporter
{
public
:
virtual
bool
ReportContext
(
const
Context
&
context
)
const
{
return
ConsoleReporter
::
ReportContext
(
context
);
};
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
report
)
const
{
++
count_
;
ConsoleReporter
::
ReportRuns
(
report
);
};
TestReporter
()
:
count_
(
0
)
{}
virtual
~
TestReporter
()
{}
size_t
GetCount
()
const
{
return
count_
;
}
private
:
mutable
size_t
count_
;
};
int
main
(
int
argc
,
const
char
*
argv
[])
{
int
main
(
int
argc
,
const
char
*
argv
[])
{
benchmark
::
Initialize
(
&
argc
,
argv
);
benchmark
::
Initialize
(
&
argc
,
argv
);
assert
(
Factorial
(
8
)
==
40320
);
assert
(
Factorial
(
8
)
==
40320
);
assert
(
CalculatePi
(
1
)
==
0.0
);
assert
(
CalculatePi
(
1
)
==
0.0
);
TestReporter
test_reporter
;
benchmark
::
RunSpecifiedBenchmarks
();
benchmark
::
RunSpecifiedBenchmarks
(
&
test_reporter
);
// Make sure we ran all of the tests
const
size_t
count
=
test_reporter
.
GetCount
();
const
size_t
expected
=
(
argc
==
2
)
?
std
::
stoul
(
argv
[
1
])
:
count
;
if
(
count
!=
expected
)
{
std
::
cerr
<<
"ERROR: Expected "
<<
expected
<<
" tests to be ran but only "
<<
count
<<
" completed"
<<
std
::
endl
;
return
-
1
;
}
}
}
test/filter_test.cc
0 → 100644
View file @
3b40f0a7
#include "benchmark/benchmark.h"
#include <assert.h>
#include <math.h>
#include <stdint.h>
#include <iostream>
#include <sstream>
#include <string>
namespace
{
double
CalculatePi
(
int
depth
)
{
double
pi
=
0.0
;
for
(
int
i
=
0
;
i
<
depth
;
++
i
)
{
double
numerator
=
static_cast
<
double
>
(((
i
%
2
)
*
2
)
-
1
);
double
denominator
=
static_cast
<
double
>
((
2
*
i
)
-
1
);
pi
+=
numerator
/
denominator
;
}
return
(
pi
-
1.0
)
*
4
;
}
class
TestReporter
:
public
benchmark
::
internal
::
ConsoleReporter
{
public
:
virtual
bool
ReportContext
(
const
Context
&
context
)
const
{
return
ConsoleReporter
::
ReportContext
(
context
);
};
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
report
)
const
{
++
count_
;
ConsoleReporter
::
ReportRuns
(
report
);
};
TestReporter
()
:
count_
(
0
)
{}
virtual
~
TestReporter
()
{}
size_t
GetCount
()
const
{
return
count_
;
}
private
:
mutable
size_t
count_
;
};
}
// end namespace
static
void
BM_CalculatePiRange
(
benchmark
::
State
&
state
)
{
double
pi
=
0.0
;
while
(
state
.
KeepRunning
())
pi
=
CalculatePi
(
state
.
range_x
());
std
::
stringstream
ss
;
ss
<<
pi
;
state
.
SetLabel
(
ss
.
str
());
}
BENCHMARK_RANGE
(
BM_CalculatePiRange
,
1
,
1024
*
1024
);
static
void
BM_CalculatePi
(
benchmark
::
State
&
state
)
{
static
const
int
depth
=
1024
;
double
pi
BENCHMARK_UNUSED
=
0.0
;
while
(
state
.
KeepRunning
())
{
pi
=
CalculatePi
(
depth
);
}
}
BENCHMARK
(
BM_CalculatePi
)
->
Threads
(
8
);
BENCHMARK
(
BM_CalculatePi
)
->
ThreadRange
(
1
,
32
);
BENCHMARK
(
BM_CalculatePi
)
->
ThreadPerCpu
();
int
main
(
int
argc
,
const
char
*
argv
[])
{
benchmark
::
Initialize
(
&
argc
,
argv
);
assert
(
CalculatePi
(
1
)
==
0.0
);
TestReporter
test_reporter
;
benchmark
::
RunSpecifiedBenchmarks
(
&
test_reporter
);
// Make sure we ran all of the tests
const
size_t
count
=
test_reporter
.
GetCount
();
const
size_t
expected
=
(
argc
==
2
)
?
std
::
stoul
(
argv
[
1
])
:
count
;
if
(
count
!=
expected
)
{
std
::
cerr
<<
"ERROR: Expected "
<<
expected
<<
" tests to be ran but only "
<<
count
<<
" completed"
<<
std
::
endl
;
return
-
1
;
}
}
test/re_test.cc
deleted
100644 → 0
View file @
522a5891
// Copyright 2015 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include "../src/re.h"
TEST
(
Regex
,
RegexSimple
)
{
benchmark
::
Regex
re
;
EXPECT_TRUE
(
re
.
Init
(
"a+"
,
NULL
));
EXPECT_FALSE
(
re
.
Match
(
""
));
EXPECT_TRUE
(
re
.
Match
(
"a"
));
EXPECT_TRUE
(
re
.
Match
(
"aa"
));
EXPECT_TRUE
(
re
.
Match
(
"baa"
));
EXPECT_FALSE
(
re
.
Match
(
"b"
));
}
TEST
(
Regex
,
RegexWildcard
)
{
benchmark
::
Regex
re
;
EXPECT_TRUE
(
re
.
Init
(
"^a*$"
,
NULL
));
EXPECT_TRUE
(
re
.
Match
(
""
));
EXPECT_TRUE
(
re
.
Match
(
"a"
));
EXPECT_TRUE
(
re
.
Match
(
"aa"
));
EXPECT_FALSE
(
re
.
Match
(
"baa"
));
EXPECT_FALSE
(
re
.
Match
(
"b"
));
}
TEST
(
Regex
,
RegexAny
)
{
benchmark
::
Regex
re
;
EXPECT_TRUE
(
re
.
Init
(
"."
,
NULL
));
EXPECT_FALSE
(
re
.
Match
(
""
));
EXPECT_TRUE
(
re
.
Match
(
"a"
));
EXPECT_TRUE
(
re
.
Match
(
"aa"
));
}
TEST
(
Regex
,
RegexExact
)
{
benchmark
::
Regex
re
;
EXPECT_TRUE
(
re
.
Init
(
"^.$"
,
NULL
));
EXPECT_FALSE
(
re
.
Match
(
""
));
EXPECT_TRUE
(
re
.
Match
(
"a"
));
EXPECT_FALSE
(
re
.
Match
(
"aa"
));
}
TEST
(
Regex
,
RegexComplicated
)
{
benchmark
::
Regex
re
;
EXPECT_TRUE
(
re
.
Init
(
"([0-9]+ )?(mon|low)key(s)?"
,
NULL
));
EXPECT_TRUE
(
re
.
Match
(
"something monkey hands"
));
EXPECT_TRUE
(
re
.
Match
(
"1 lowkey"
));
EXPECT_TRUE
(
re
.
Match
(
"19 monkeys"
));
EXPECT_FALSE
(
re
.
Match
(
"09 a"
));
}
TEST
(
Regex
,
InvalidNoErrorMessage
)
{
benchmark
::
Regex
re
;
EXPECT_FALSE
(
re
.
Init
(
"["
,
NULL
));
}
TEST
(
Regex
,
Invalid
)
{
std
::
string
error
;
benchmark
::
Regex
re
;
EXPECT_FALSE
(
re
.
Init
(
"["
,
&
error
));
EXPECT_NE
(
""
,
error
);
}
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