redo filter test

This commit is contained in:
Eric Fiselier 2015-03-31 00:05:02 -04:00
parent 12f1c5f471
commit e97a96f9e7
2 changed files with 45 additions and 42 deletions

View File

@ -13,25 +13,30 @@ endmacro(compile_benchmark_test)
# Demonstration executable
compile_benchmark_test(benchmark_test)
add_test(benchmark benchmark_test --benchmark_min_time=0.1)
add_test(benchmark benchmark_test --benchmark_min_time=0.01)
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)
macro(add_filter_test name filter expect)
add_test(${name} filter_test --benchmark_min_time=0.01 --benchmark_filter=${filter} ${expect})
endmacro(add_filter_test)
add_filter_test(filter_simple "Foo" 3)
add_filter_test(filter_suffix "BM_.*" 4)
add_filter_test(filter_regex_all ".*" 5)
add_filter_test(filter_regex_blank "" 5)
add_filter_test(filter_regex_none "monkey" 0)
add_filter_test(filter_regex_wildcard ".*Foo.*" 3)
add_filter_test(filter_regex_begin "^BM_.*" 4)
add_filter_test(filter_regex_begin2 "^N" 1)
add_filter_test(filter_regex_end ".*Ba$" 1)
compile_benchmark_test(options_test)
add_test(options_benchmarks options_test)
add_test(options_benchmarks options_test --benchmark_min_time=0.01)
compile_benchmark_test(basic_test)
add_test(basic_benchmark basic_test)
add_test(basic_benchmark basic_test --benchmark_min_time=0.01)
compile_benchmark_test(cxx03_test)
set_target_properties(cxx03_test
PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
add_test(cxx03 cxx03_test)
add_test(cxx03 cxx03_test --benchmark_min_time=0.01)

View File

@ -11,16 +11,6 @@
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::ConsoleReporter {
public:
virtual bool ReportContext(const Context& context) {
@ -46,32 +36,40 @@ class TestReporter : public benchmark::ConsoleReporter {
} // 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);
}
static void NoPrefix(benchmark::State& state) {
while (state.KeepRunning()) {}
}
BENCHMARK(BM_CalculatePi)->Threads(8);
BENCHMARK(BM_CalculatePi)->ThreadRange(1, 32);
BENCHMARK(BM_CalculatePi)->ThreadPerCpu();
BENCHMARK(NoPrefix);
static void BM_Foo(benchmark::State& state) {
while (state.KeepRunning()) {}
}
BENCHMARK(BM_Foo);
static void BM_Bar(benchmark::State& state) {
while (state.KeepRunning()) {}
}
BENCHMARK(BM_Bar);
static void BM_FooBar(benchmark::State& state) {
while (state.KeepRunning()) {}
}
BENCHMARK(BM_FooBar);
static void BM_FooBa(benchmark::State& state) {
while (state.KeepRunning()) {}
}
BENCHMARK(BM_FooBa);
int main(int argc, const char* argv[]) {
benchmark::Initialize(&argc, argv);
assert(std::fabs(CalculatePi(1)) < std::numeric_limits<float>::epsilon());
TestReporter test_reporter;
benchmark::RunSpecifiedBenchmarks(&test_reporter);