diff --git a/benchmark/run.cpp b/benchmark/run.cpp index 3df57976e..24799ed35 100644 --- a/benchmark/run.cpp +++ b/benchmark/run.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #define BOOST_CHRONO_HEADER_ONLY #include @@ -40,32 +39,40 @@ void benchmark(T & test_runner, std::string const& name) { try { bool should_run_test = true; - if (!test_set.empty()) { + if (!test_set.empty()) + { should_run_test = test_set.find(test_num) != test_set.end(); } - if (should_run_test || dry_run) { - if (!test_runner.validate()) { + if (should_run_test || dry_run) + { + 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) { + if (dry_run) + { std::clog << test_num << ") " << (test_runner.threads_ ? "threaded -> ": "") << name << "\n"; - } else { + } + else + { process_cpu_clock::time_point start; dur elapsed; - if (test_runner.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); + tg.create_thread(test_runner); + //tg.create_thread(boost::bind(&T::operator(),&test_runner)); } start = process_cpu_clock::now(); tg.join_all(); elapsed = process_cpu_clock::now() - start; - } else { + } + else + { start = process_cpu_clock::now(); test_runner(); elapsed = process_cpu_clock::now() - start; @@ -75,7 +82,9 @@ void benchmark(T & test_runner, std::string const& name) << boost::chrono::duration_cast(elapsed) << "\n"; } } - } catch (std::exception const& ex) { + } + catch (std::exception const& ex) + { std::clog << "test runner did not complete: " << ex.what() << "\n"; } test_num++; @@ -594,6 +603,7 @@ struct test10 } }; + #include #include "agg_conv_clipper.h" #include "agg_path_storage.h" @@ -603,21 +613,19 @@ struct test11 { unsigned iter_; unsigned threads_; - boost::ptr_vector paths_; + std::string wkt_in_; 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"); - } - } + test11(unsigned iterations, + unsigned threads, + std::string wkt_in, + mapnik::box2d const& extent) + : iter_(iterations), + threads_(threads), + wkt_in_(wkt_in), + extent_(extent) { + + } bool validate() { @@ -625,6 +633,11 @@ struct test11 } void operator()() { + boost::ptr_vector paths; + if (!mapnik::from_wkt(wkt_in_, paths)) + { + throw std::runtime_error("Failed to parse WKT"); + } agg::path_storage ps; ps.move_to(extent_.minx(), extent_.miny()); ps.line_to(extent_.minx(), extent_.maxy()); @@ -632,7 +645,7 @@ struct test11 ps.line_to(extent_.maxx(), extent_.miny()); ps.close_polygon(); for (unsigned i=0;i + +struct test12 +{ + unsigned iter_; + unsigned threads_; + std::string wkt_in_; + + mapnik::box2d extent_; + typedef mapnik::polygon_clipper poly_clipper; + test12(unsigned iterations, + unsigned threads, + std::string wkt_in, + mapnik::box2d const& extent) + : iter_(iterations), + threads_(threads), + wkt_in_(wkt_in), + extent_(extent) + { + } + + bool validate() + { + return true; + } + void operator()() + { + boost::ptr_vector paths; + if (!mapnik::from_wkt(wkt_in_, paths)) + { + throw std::runtime_error("Failed to parse WKT"); + } + for (unsigned i=0;i 0) { @@ -785,10 +843,25 @@ int main( int argc, char** argv) 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::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); + + test12 runner(100000,10,wkt_in,clipping_box); + benchmark(runner,"clipping polygon with mapnik::polygon_clipper"); + } + std::cout << "...benchmark done\n"; return 0; }