From b9cbfe9dcee55964ff908cf6a1b72741c03cc246 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 27 Feb 2013 19:18:28 -0500 Subject: [PATCH] benchmark: avoid copying test struct and add test of clipper --- benchmark/data/polygon.wkt | 1 + benchmark/run.cpp | 85 ++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 benchmark/data/polygon.wkt diff --git a/benchmark/data/polygon.wkt b/benchmark/data/polygon.wkt new file mode 100644 index 000000000..2fe5b480a --- /dev/null +++ b/benchmark/data/polygon.wkt @@ -0,0 +1 @@ +MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5))) \ No newline at end of file diff --git a/benchmark/run.cpp b/benchmark/run.cpp index daead8897..3df57976e 100644 --- a/benchmark/run.cpp +++ b/benchmark/run.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #define BOOST_CHRONO_HEADER_ONLY #include @@ -35,7 +36,7 @@ typedef process_cpu_clock clock_type; typedef clock_type::duration dur; template -void benchmark(T test, std::string const& name) +void benchmark(T & test_runner, std::string const& name) { try { bool should_run_test = true; @@ -43,31 +44,33 @@ void benchmark(T test, std::string const& name) should_run_test = test_set.find(test_num) != test_set.end(); } if (should_run_test || dry_run) { - if (!test.validate()) { + if (!test_runner.validate()) { std::clog << "test did not validate: " << name << "\n"; //throw std::runtime_error(std::string("test did not validate: ") + name); } if (dry_run) { - std::clog << test_num << ") " << (test.threads_ ? "threaded -> ": "") + std::clog << test_num << ") " << (test_runner.threads_ ? "threaded -> ": "") << name << "\n"; } else { process_cpu_clock::time_point start; dur elapsed; - if (test.threads_ > 0) { + if (test_runner.threads_ > 0) { boost::thread_group tg; - for (unsigned i=0;i _p; + _p = boost::bind(&T::operator(),&test_runner); + tg.create_thread(_p); } start = process_cpu_clock::now(); tg.join_all(); elapsed = process_cpu_clock::now() - start; } else { start = process_cpu_clock::now(); - test(); + test_runner(); elapsed = process_cpu_clock::now() - start; } - std::clog << test_num << ") " << (test.threads_ ? "threaded -> ": "") + std::clog << test_num << ") " << (test_runner.threads_ ? "threaded -> ": "") << name << ": " << boost::chrono::duration_cast(elapsed) << "\n"; } @@ -591,6 +594,60 @@ struct test10 } }; +#include +#include "agg_conv_clipper.h" +#include "agg_path_storage.h" +#include + +struct test11 +{ + unsigned iter_; + unsigned threads_; + boost::ptr_vector paths_; + mapnik::box2d extent_; + typedef agg::conv_clipper poly_clipper; + explicit test11(unsigned iterations, + unsigned threads, + std::string wkt_in, + mapnik::box2d const& extent) + : iter_(iterations), + threads_(threads), + extent_(extent) { + if (!mapnik::from_wkt(wkt_in, paths_)) + { + throw std::runtime_error("Failed to parse WKT"); + } + } + + bool validate() + { + return true; + } + void operator()() + { + agg::path_storage ps; + ps.move_to(extent_.minx(), extent_.miny()); + ps.line_to(extent_.minx(), extent_.maxy()); + ps.line_to(extent_.maxx(), extent_.maxy()); + ps.line_to(extent_.maxx(), extent_.miny()); + ps.close_polygon(); + for (unsigned i=0;i 0) { @@ -720,6 +777,18 @@ int main( int argc, char** argv) benchmark(runner,"rule caching using heap allocation"); } + { + std::string filename_("benchmark/data/polygon.wkt"); + std::ifstream in(filename_.c_str(),std::ios_base::in | std::ios_base::binary); + if (!in.is_open()) + throw std::runtime_error("could not open: '" + filename_ + "'"); + std::string wkt_in( (std::istreambuf_iterator(in) ), + (std::istreambuf_iterator()) ); + mapnik::box2d clipping_box(0,0,40,40); + test11 runner(100000,10,wkt_in,clipping_box); + benchmark(runner,"clipping polygon with agg_conv_clipper"); + } + std::cout << "...benchmark done\n"; return 0; }