From 2f303e4da48238c136fdc3ddd1019eac0e21b678 Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Tue, 16 Feb 2016 19:53:03 +0100 Subject: [PATCH] benchmarks: helper class for running a sequence of tests --- benchmark/bench_framework.hpp | 28 ++++++++ benchmark/test_array_allocation.cpp | 71 ++++--------------- .../test_numeric_cast_vs_static_cast.cpp | 16 ++--- benchmark/test_polygon_clipping_rendering.cpp | 32 ++------- benchmark/test_proj_transform1.cpp | 38 ++-------- 5 files changed, 59 insertions(+), 126 deletions(-) diff --git a/benchmark/bench_framework.hpp b/benchmark/bench_framework.hpp index 8eb01ce85..c78125149 100644 --- a/benchmark/bench_framework.hpp +++ b/benchmark/bench_framework.hpp @@ -186,6 +186,34 @@ int run(T const& test_runner, std::string const& name) return 0; } +struct sequencer +{ + sequencer(int argc, char** argv) + : exit_code_(0) + { + benchmark::handle_args(argc, argv, params_); + } + + int done() const + { + return exit_code_; + } + + template + sequencer & run(std::string const& name, Args && ...args) + { + // Test instance lifetime is confined to this function + Test test_runner(params_, std::forward(args)...); + // any failing test run will make exit code non-zero + exit_code_ |= benchmark::run(test_runner, name); + return *this; // allow chaining calls + } + +protected: + mapnik::parameters params_; + int exit_code_; +}; + } #endif // __MAPNIK_BENCH_FRAMEWORK_HPP__ diff --git a/benchmark/test_array_allocation.cpp b/benchmark/test_array_allocation.cpp index e11a68fd8..186c1620e 100644 --- a/benchmark/test_array_allocation.cpp +++ b/benchmark/test_array_allocation.cpp @@ -359,62 +359,21 @@ public: int main(int argc, char** argv) { - int return_value = 0; - mapnik::parameters params; - benchmark::handle_args(argc,argv,params); - { - test4 test_runner4(params); - return_value = return_value | run(test_runner4,"calloc"); - } - { - test1 test_runner(params); - return_value = return_value | run(test_runner,"malloc/memcpy"); - } - { - test1b test_runner(params); - return_value = return_value | run(test_runner,"malloc/memset"); - } - { - test1c test_runner(params); - return_value = return_value | run(test_runner,"operator new/std::fill"); - } - { - test2 test_runner(params); - return_value = return_value | run(test_runner,"operator new/memcpy"); - } - { - test3 test_runner(params); - return_value = return_value | run(test_runner,"vector(N)"); - } - { - test3b test_runner(params); - return_value = return_value | run(test_runner,"vector/resize"); - } - { - test3c test_runner(params); - return_value = return_value | run(test_runner,"vector/assign"); - } - { - test3d test_runner(params); - return_value = return_value | run(test_runner,"deque(N)"); - } - { - test5 test_runner(params); - return_value = return_value | run(test_runner,"std::string range"); - } - { - test5b test_runner(params); - return_value = return_value | run(test_runner,"std::string &[0]"); - } - { - test6 test_runner(params); - return_value = return_value | run(test_runner,"valarray"); - } + return benchmark::sequencer(argc, argv) + .run("calloc") + .run("malloc/memcpy") + .run("malloc/memset") + .run("operator new/std::fill") + .run("operator new/memcpy") + .run("vector(N)") + .run("vector/resize") + .run("vector/assign") + .run("deque(N)") + .run("std::string range") + .run("std::string &[0]") + .run("valarray") #if BOOST_VERSION >= 105400 - { - test7 test_runner(params); - return_value = return_value | run(test_runner,"static_vector"); - } + .run("static_vector") #endif - return return_value; + .done(); } diff --git a/benchmark/test_numeric_cast_vs_static_cast.cpp b/benchmark/test_numeric_cast_vs_static_cast.cpp index 8ea6e6be1..9e14bf31e 100644 --- a/benchmark/test_numeric_cast_vs_static_cast.cpp +++ b/benchmark/test_numeric_cast_vs_static_cast.cpp @@ -73,16 +73,8 @@ public: int main(int argc, char** argv) { - mapnik::parameters params; - benchmark::handle_args(argc,argv,params); - int return_value = 0; - { - test_static test_runner(params); - return_value = return_value | run(test_runner,"static_cast"); - } - { - test_numeric test_runner(params); - return_value = return_value | run(test_runner,"numeric_cast"); - } - return return_value; + return benchmark::sequencer(argc, argv) + .run("static_cast") + .run("numeric_cast") + .done(); } diff --git a/benchmark/test_polygon_clipping_rendering.cpp b/benchmark/test_polygon_clipping_rendering.cpp index ab23459c4..758505d9d 100644 --- a/benchmark/test_polygon_clipping_rendering.cpp +++ b/benchmark/test_polygon_clipping_rendering.cpp @@ -51,30 +51,10 @@ int main(int argc, char** argv) mapnik::box2d z1(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298); // bbox for 16/10491/22911.png mapnik::box2d z16(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214); - int return_value = 0; - { - test test_runner(params, - "benchmark/data/polygon_rendering_clip.xml", - z1); - return_value = return_value | run(test_runner,"polygon clip render z1"); - } - { - test test_runner(params, - "benchmark/data/polygon_rendering_no_clip.xml", - z1); - return_value = return_value | run(test_runner,"polygon noclip render z1"); - } - { - test test_runner(params, - "benchmark/data/polygon_rendering_clip.xml", - z16); - return_value = return_value | run(test_runner,"polygon clip render z16"); - } - { - test test_runner(params, - "benchmark/data/polygon_rendering_no_clip.xml", - z16); - return_value = return_value | run(test_runner,"polygon noclip render z16"); - } - return return_value; + return benchmark::sequencer(argc, argv) + .run("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1) + .run("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1) + .run("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16) + .run("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16) + .done(); } diff --git a/benchmark/test_proj_transform1.cpp b/benchmark/test_proj_transform1.cpp index 451c51ae1..37f4b0c4c 100644 --- a/benchmark/test_proj_transform1.cpp +++ b/benchmark/test_proj_transform1.cpp @@ -59,42 +59,16 @@ public: // echo -180 -60 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857 int main(int argc, char** argv) { - mapnik::parameters params; - benchmark::handle_args(argc,argv,params); mapnik::box2d from(-180,-80,180,80); mapnik::box2d to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316); std::string from_str("+init=epsg:4326"); std::string to_str("+init=epsg:3857"); std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"); std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"); - int return_value = 0; - test test_runner(params, - from_str, - to_str, - from, - to, - true); - return_value = return_value | run(test_runner,"lonlat->merc epsg"); - test test_runner2(params, - from_str2, - to_str2, - from, - to, - true); - return_value = return_value | run(test_runner2,"lonlat->merc literal"); - test test_runner3(params, - to_str, - from_str, - to, - from, - true); - return_value = return_value | run(test_runner3,"merc->lonlat epsg"); - test test_runner4(params, - to_str2, - from_str2, - to, - from, - true); - return_value = return_value | run(test_runner4,"merc->lonlat literal"); - return return_value; + return benchmark::sequencer(argc, argv) + .run("lonlat->merc epsg", from_str, to_str, from, to, true) + .run("lonlat->merc literal", from_str2, to_str2, from, to, true) + .run("merc->lonlat epsg", to_str, from_str, to, from, true) + .run("merc->lonlat literal", to_str2, from_str2, to, from, true) + .done(); }