Commit e97a96f9 by Eric Fiselier

redo filter test

parent 12f1c5f4
...@@ -13,25 +13,30 @@ endmacro(compile_benchmark_test) ...@@ -13,25 +13,30 @@ endmacro(compile_benchmark_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) add_test(benchmark benchmark_test --benchmark_min_time=0.01)
compile_benchmark_test(filter_test) compile_benchmark_test(filter_test)
add_test(filter_simple filter_test --benchmark_filter=Calculate 16) macro(add_filter_test name filter expect)
add_test(filter_suffix filter_test --benchmark_filter=Calculate* 16) add_test(${name} filter_test --benchmark_min_time=0.01 --benchmark_filter=${filter} ${expect})
add_test(filter_regex_all filter_test --benchmark_filter=.* 16) endmacro(add_filter_test)
add_test(filter_regex_blank filter_test --benchmark_filter= 16)
add_test(filter_regex_none filter_test --benchmark_filter=monkey 0) add_filter_test(filter_simple "Foo" 3)
add_test(filter_regex_wildcard filter_test --benchmark_filter=.*Calculate.* 16) add_filter_test(filter_suffix "BM_.*" 4)
add_test(filter_regex_begin filter_test --benchmark_filter=^BM_Calculate.* 16) add_filter_test(filter_regex_all ".*" 5)
add_test(filter_regex_end filter_test --benchmark_filter=.*Pi$ 8) 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) 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) 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) compile_benchmark_test(cxx03_test)
set_target_properties(cxx03_test set_target_properties(cxx03_test
PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}") PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
add_test(cxx03 cxx03_test) add_test(cxx03 cxx03_test --benchmark_min_time=0.01)
...@@ -11,16 +11,6 @@ ...@@ -11,16 +11,6 @@
namespace { 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 { class TestReporter : public benchmark::ConsoleReporter {
public: public:
virtual bool ReportContext(const Context& context) { virtual bool ReportContext(const Context& context) {
...@@ -46,32 +36,40 @@ class TestReporter : public benchmark::ConsoleReporter { ...@@ -46,32 +36,40 @@ class TestReporter : public benchmark::ConsoleReporter {
} // end namespace } // end namespace
static void BM_CalculatePiRange(benchmark::State& state) {
double pi = 0.0; static void NoPrefix(benchmark::State& state) {
while (state.KeepRunning()) while (state.KeepRunning()) {}
pi = CalculatePi(state.range_x());
std::stringstream ss;
ss << pi;
state.SetLabel(ss.str());
} }
BENCHMARK_RANGE(BM_CalculatePiRange, 1, 1024 * 1024); BENCHMARK(NoPrefix);
static void BM_CalculatePi(benchmark::State& state) { static void BM_Foo(benchmark::State& state) {
static const int depth = 1024; while (state.KeepRunning()) {}
double pi BENCHMARK_UNUSED = 0.0;
while (state.KeepRunning()) {
pi = CalculatePi(depth);
}
} }
BENCHMARK(BM_CalculatePi)->Threads(8); BENCHMARK(BM_Foo);
BENCHMARK(BM_CalculatePi)->ThreadRange(1, 32);
BENCHMARK(BM_CalculatePi)->ThreadPerCpu();
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[]) { int main(int argc, const char* argv[]) {
benchmark::Initialize(&argc, argv); benchmark::Initialize(&argc, argv);
assert(std::fabs(CalculatePi(1)) < std::numeric_limits<float>::epsilon());
TestReporter test_reporter; TestReporter test_reporter;
benchmark::RunSpecifiedBenchmarks(&test_reporter); benchmark::RunSpecifiedBenchmarks(&test_reporter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment