From e504383a157de7d8ed5a1ade0dc687f565b0bbf7 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 29 Jan 2013 03:06:44 -0500 Subject: [PATCH 1/6] benchmark: enable more transformation tests since proj4 is no longer the bottleneck for key transformations - refs #1703 --- benchmark/run.cpp | 102 ++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/benchmark/run.cpp b/benchmark/run.cpp index 4e190b227..1c4ea6e40 100644 --- a/benchmark/run.cpp +++ b/benchmark/run.cpp @@ -36,39 +36,43 @@ typedef clock_type::duration dur; template void benchmark(T test, std::string const& name) { - bool should_run_test = true; - if (!test_set.empty()) { - should_run_test = test_set.find(test_num) != test_set.end(); - } - if (should_run_test || dry_run) { - if (!test.validate()) { - std::clog << "test did not validate: " << name << "\n"; - //throw std::runtime_error(std::string("test did not validate: ") + name); + try { + bool should_run_test = true; + if (!test_set.empty()) { + should_run_test = test_set.find(test_num) != test_set.end(); } - if (dry_run) { - std::clog << test_num << ") " << (test.threads_ ? "threaded -> ": "") - << name << "\n"; - } else { - process_cpu_clock::time_point start; - dur elapsed; - if (test.threads_ > 0) { - boost::thread_group tg; - for (unsigned i=0;i ": "") + << name << "\n"; + } else { + process_cpu_clock::time_point start; + dur elapsed; + if (test.threads_ > 0) { + boost::thread_group tg; + for (unsigned i=0;i ": "") + << name << ": " + << boost::chrono::duration_cast(elapsed) << "\n"; } - std::clog << test_num << ") " << (test.threads_ ? "threaded -> ": "") - << name << ": " - << boost::chrono::duration_cast(elapsed) << "\n"; } + } catch (std::exception const& ex) { + std::clog << "test runner did not complete: " << ex.what() << "\n"; } test_num++; } @@ -402,27 +406,11 @@ int main( int argc, char** argv) mapnik::box2d to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316); { - test6 runner(1,5, - "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", - "+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", - from,to,false); - benchmark(runner,"lonlat -> merc coord transformation with proj4 init (literal)"); - } - - { - test6 runner(1,5, - "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", - "+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", - from,to,true); - benchmark(runner,"lonlat -> merc coord transformation with lazy proj4 init (literal)"); - } - - /*{ // echo -180 -60 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857 test6 runner(100000000,100, "+init=epsg:4326", "+init=epsg:3857", - from,to,false); + from,to,true); benchmark(runner,"lonlat -> merc coord transformation (epsg)"); } @@ -430,17 +418,25 @@ int main( int argc, char** argv) test6 runner(100000000,100, "+init=epsg:3857", "+init=epsg:4326", - to,from,false); + to,from,true); benchmark(runner,"merc -> lonlat coord transformation (epsg)"); - }*/ + } - /*{ - test6 runner(10,2, + { + test6 runner(100000000,100, + "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", + "+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", + from,to,true); + benchmark(runner,"lonlat -> merc coord transformation (literal)"); + } + + { + test6 runner(100000000,100, "+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", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", - to,from,false); + to,from,true); benchmark(runner,"merc -> lonlat coord transformation (literal)"); - }*/ + } std::cout << "...benchmark done\n"; return 0; From 98e974e956a60c0501da96e8e48010efecc2248d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 29 Jan 2013 03:30:01 -0500 Subject: [PATCH 2/6] fix ifdef logic --- src/image_util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image_util.cpp b/src/image_util.cpp index 9b8ec651a..59888faec 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -348,7 +348,7 @@ void save_to_stream(T const& image, } else if (boost::algorithm::starts_with(t, "tif")) { -#if defined(HAVE_JPEG) +#if defined(HAVE_TIFF) save_as_tiff(stream, image); #else throw ImageWriterException("tiff output is not enabled in your build of Mapnik"); From 409b35db6f782fb01c56bc23b29e20321df3d97a Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 29 Jan 2013 03:30:22 -0500 Subject: [PATCH 3/6] benchmark: fix iterator advance --- benchmark/run.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/run.cpp b/benchmark/run.cpp index 2df0d0981..1c97d0d5f 100644 --- a/benchmark/run.cpp +++ b/benchmark/run.cpp @@ -313,7 +313,7 @@ struct test6 mapnik::projection dest(dest_); mapnik::proj_transform tr(src,dest); unsigned count=0; - for (int i=-180;i<180;i=++i) + for (int i=-180;i<180;++i) { for (int j=-85;j<85;++j) { From 92b0e43d87996a47d6c960ba6a9eea51ded429ab Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 29 Jan 2013 03:36:38 -0500 Subject: [PATCH 4/6] remove mutex around pj_transform --- src/proj_transform.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 060fbdc63..9972ca4ae 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -113,15 +113,10 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou } } + if (pj_transform( source_.proj_, dest_.proj_, point_count, + 0, x,y,z) != 0) { -#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480 - mutex::scoped_lock lock(projection::mutex_); -#endif - if (pj_transform( source_.proj_, dest_.proj_, point_count, - 0, x,y,z) != 0) - { - return false; - } + return false; } if (is_dest_longlat_) @@ -160,16 +155,10 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co } } + if (pj_transform( dest_.proj_, source_.proj_, point_count, + 0, x,y,z) != 0) { -#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480 - mutex::scoped_lock lock(projection::mutex_); -#endif - - if (pj_transform( dest_.proj_, source_.proj_, point_count, - 0, x,y,z) != 0) - { - return false; - } + return false; } if (is_source_longlat_) From 8c8df19cc743f097f1d119d9a0e4423599c93c0c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 29 Jan 2013 17:04:35 -0500 Subject: [PATCH 5/6] benchmark: add tests for expression grammar parsing - refs #1706 --- benchmark/run.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/benchmark/run.cpp b/benchmark/run.cpp index 3dc30f044..4bc35d6ad 100644 --- a/benchmark/run.cpp +++ b/benchmark/run.cpp @@ -332,6 +332,65 @@ struct test6 } }; +#include +#include +#include + +struct test7 +{ + unsigned iter_; + unsigned threads_; + std::string expr_; + explicit test7(unsigned iterations, + unsigned threads, + std::string const& expr) : + iter_(iterations), + threads_(threads), + expr_(expr) + {} + + bool validate() + { + mapnik::expression_ptr expr = mapnik::parse_expression(expr_,"utf-8"); + return mapnik::to_expression_string(*expr) == expr_; + } + void operator()() + { + for (int i=0;i + +struct test8 +{ + unsigned iter_; + unsigned threads_; + std::string expr_; + explicit test8(unsigned iterations, + unsigned threads, + std::string const& expr) : + iter_(iterations), + threads_(threads), + expr_(expr) + {} + + bool validate() + { + mapnik::expression_grammar expr_grammar(transcoder("utf-8")); + mapnik::expression_ptr expr = mapnik::parse_expression(expr_,expr_grammar); + return mapnik::to_expression_string(*expr) == expr_; + } + void operator()() + { + mapnik::expression_grammar expr_grammar(transcoder("utf-8")); + for (int i=0;i lonlat coord transformation (literal)"); } + { + test7 runner(10000,100,"([foo]=1)"); + benchmark(runner,"expression parsing with grammer per parse"); + } + + { + test8 runner(10000,100,"([foo]=1)"); + benchmark(runner,"expression parsing by re-using grammar"); + } + std::cout << "...benchmark done\n"; return 0; } From 1356775299bfd5806b76a4a8067b93fba03c7dca Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 29 Jan 2013 17:23:10 -0500 Subject: [PATCH 6/6] scons: remove uneeded BOOST_SPIRIT_THREADSAFE flag - closes #1706 --- SConstruct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 923a03f68..a2e0385c3 100644 --- a/SConstruct +++ b/SConstruct @@ -1491,7 +1491,7 @@ if not preconfigured: # Common C++ flags. if env['THREADING'] == 'multi': - common_cxx_flags = '-D%s -DBOOST_SPIRIT_THREADSAFE -DMAPNIK_THREADSAFE ' % env['PLATFORM'].upper() + common_cxx_flags = '-D%s -DMAPNIK_THREADSAFE ' % env['PLATFORM'].upper() else : common_cxx_flags = '-D%s ' % env['PLATFORM'].upper()