diff --git a/Makefile b/Makefile index 8c05035d5..815d1902a 100755 --- a/Makefile +++ b/Makefile @@ -61,8 +61,7 @@ test-local: make test bench: - @export ${LINK_FIX}=`pwd`/src:${${LINK_FIX}} && \ - ./benchmark/run + @./benchmark/run check: test-local diff --git a/benchmark/allocation.cpp b/benchmark/allocation.cpp deleted file mode 100644 index 1b058df84..000000000 --- a/benchmark/allocation.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include - - -#define BOOST_CHRONO_HEADER_ONLY -#include -#include - -using namespace boost::chrono; -using namespace mapnik; - -void threaded_benchmark(void test(),std::string const& name, unsigned num_threads) { - using namespace boost::chrono; - typedef process_cpu_clock clock_type; - process_real_cpu_clock::time_point start = process_real_cpu_clock::now(); - //boost::thread_group threads; - typedef std::vector > thread_group; - typedef thread_group::value_type value_type; - thread_group threads; - // create threads - for (unsigned i=0; ijoinable()) t->join();}); - - clock_type::duration elapsed = process_real_cpu_clock::now() - start; - std::clog << boost::chrono::duration_cast(elapsed) - << " (" << boost::chrono::duration_cast(elapsed) << ")" - << " <-- " << name << "\n"; -} - - -void test_wkt_creation() -{ - boost::ptr_vector paths; - mapnik::wkt_parser parse_wkt; - std::string value("GEOMETRYCOLLECTION(MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20))),POINT(2 3),LINESTRING(2 3,3 4),MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20))),MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20))),MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20))))"); - if (!parse_wkt.parse(value, paths)) std::clog << "failed to parse\n"; - int iterations = 10000; - typedef process_cpu_clock clock_type; - process_real_cpu_clock::time_point start = process_real_cpu_clock::now(); - for (int i=0;i(elapsed) << "\n"; -} - -int main( int, char*[] ) -{ - return 0; -} diff --git a/benchmark/bench_framework.hpp b/benchmark/bench_framework.hpp new file mode 100644 index 000000000..a0de28bca --- /dev/null +++ b/benchmark/bench_framework.hpp @@ -0,0 +1,119 @@ +#ifndef __MAPNIK_BENCH_FRAMEWORK_HPP__ +#define __MAPNIK_BENCH_FRAMEWORK_HPP__ + +// mapnik +#include +#include + +// boost +#define BOOST_CHRONO_HEADER_ONLY +#include +#include + +// stl +#include +#include +#include +#include + +namespace benchmark { + +class test_case +{ +protected: + mapnik::parameters params_; + std::size_t threads_; + std::size_t iterations_; +public: + test_case(mapnik::parameters const& params) + : params_(params), + threads_(*params.get("threads",0)), + iterations_(*params.get("iterations",0)) + {} + std::size_t threads() const + { + return threads_; + } + std::size_t iterations() const + { + return iterations_; + } + virtual bool validate() const = 0; + virtual void operator()() const = 0; + virtual ~test_case() {} +}; + +void handle_args(int argc, char** argv, mapnik::parameters & params) +{ + if (argc > 0) { + for (int i=1;i +int run(T const& test_runner, std::string const& name) +{ + try + { + if (!test_runner.validate()) + { + std::clog << "test did not validate: " << name << "\n"; + return -1; + } + boost::chrono::process_cpu_clock::time_point start; + boost::chrono::process_cpu_clock::duration elapsed; + std::clog << name << ": "; + if (test_runner.threads() > 0) + { + typedef std::vector > thread_group; + typedef thread_group::value_type value_type; + thread_group tg; + for (std::size_t i=0;ijoinable()) t->join();}); + elapsed = boost::chrono::process_cpu_clock::now() - start; + } + else + { + start = boost::chrono::process_cpu_clock::now(); + test_runner(); + elapsed = boost::chrono::process_cpu_clock::now() - start; + } + std::clog << boost::chrono::duration_cast(elapsed) + << " t:" << test_runner.threads() + << " i:" << test_runner.iterations() << "\n"; + return 0; + } + catch (std::exception const& ex) + { + std::clog << "test runner did not complete: " << ex.what() << "\n"; + return -1; + } + return 0; +} + +} + +#endif // __MAPNIK_BENCH_FRAMEWORK_HPP__ \ No newline at end of file diff --git a/benchmark/build.py b/benchmark/build.py index 5fa4fdba4..ca2eb7f30 100644 --- a/benchmark/build.py +++ b/benchmark/build.py @@ -8,17 +8,16 @@ test_env = env.Clone() test_env['LIBS'] = copy(env['LIBMAPNIK_LIBS']) test_env.AppendUnique(LIBS='mapnik') -#test_env.AppendUnique(LIBS='sqlite3') test_env.AppendUnique(CXXFLAGS='-g') +if 'g++' in env['CXX']: + test_env.Append(CXXFLAGS='-fPIC') if env['PLATFORM'] == 'Darwin': test_env.Append(LINKFLAGS='-F/ -framework CoreFoundation') -for cpp_test in glob.glob('run*.cpp'): - name = cpp_test.replace('.cpp','') - source_files = [cpp_test] - test_env_local = test_env.Clone() - test_program = test_env_local.Program(name, source=source_files) - Depends(test_program, env.subst('../src/%s' % env['MAPNIK_LIB_NAME'])) - # build locally if installing +test_env_local = test_env.Clone() + +for cpp_test in glob.glob('*cpp'): + test_program = test_env_local.Program('out/'+cpp_test.replace('.cpp',''), source=[cpp_test]) if 'install' in COMMAND_LINE_TARGETS: env.Alias('install',test_program) + #Depends(test_program, env.subst('../src/%s' % env['MAPNIK_LIB_NAME'])) diff --git a/benchmark/compare_images.hpp b/benchmark/compare_images.hpp new file mode 100644 index 000000000..8e4f17740 --- /dev/null +++ b/benchmark/compare_images.hpp @@ -0,0 +1,51 @@ +#ifndef __MAPNIK_COMPARE_IMAGES_HPP__ +#define __MAPNIK_COMPARE_IMAGES_HPP__ + +#include +#include +#include +#include + +using namespace mapnik; + +namespace benchmark { + + bool compare_images(std::string const& src_fn,std::string const& dest_fn) + { + std::unique_ptr reader1(mapnik::get_image_reader(dest_fn,"png")); + if (!reader1.get()) + { + throw mapnik::image_reader_exception("Failed to load: " + dest_fn); + } + std::shared_ptr image_ptr1 = std::make_shared(reader1->width(),reader1->height()); + reader1->read(0,0,image_ptr1->data()); + + std::unique_ptr reader2(mapnik::get_image_reader(src_fn,"png")); + if (!reader2.get()) + { + throw mapnik::image_reader_exception("Failed to load: " + src_fn); + } + std::shared_ptr image_ptr2 = std::make_shared(reader2->width(),reader2->height()); + reader2->read(0,0,image_ptr2->data()); + + image_data_32 const& dest = image_ptr1->data(); + image_data_32 const& src = image_ptr2->data(); + + unsigned int width = src.width(); + unsigned int height = src.height(); + if ((width != dest.width()) || height != dest.height()) return false; + for (unsigned int y = 0; y < height; ++y) + { + const unsigned int* row_from = src.getRow(y); + const unsigned int* row_to = dest.getRow(y); + for (unsigned int x = 0; x < width; ++x) + { + if (row_from[x] != row_to[x]) return false; + } + } + return true; + } + +} + +#endif // __MAPNIK_COMPARE_IMAGES_HPP__ \ No newline at end of file diff --git a/benchmark/run b/benchmark/run new file mode 100755 index 000000000..e9b3c72cc --- /dev/null +++ b/benchmark/run @@ -0,0 +1,17 @@ +#!/bin/sh + +cd "$( dirname "${BASH_SOURCE[0]}" )" +cd ../ +BASE=./benchmark/out +function run { + ${BASE}/$1 --threads 0 --iterations $3; + ${BASE}/$1 --threads $2 --iterations $(expr $3 / $2); +} + +run test_png_encoding1 10 1000 +run test_png_encoding2 10 50 +run test_to_string1 10 100000 +run test_to_string2 10 100000 +run test_proj_transform1 10 100 +run test_expression_parse 10 10000 + diff --git a/benchmark/run.cpp b/benchmark/run.cpp deleted file mode 100644 index 995a450f9..000000000 --- a/benchmark/run.cpp +++ /dev/null @@ -1,934 +0,0 @@ -#include -#include -#include -#include -#include - - -// stl -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// boost -#include -#include - -#define BOOST_CHRONO_HEADER_ONLY -#include -#include - -using namespace boost::chrono; -using namespace mapnik; - -static bool dry_run = false; -typedef std::set set_type; -static set_type test_set; -static set_type::key_type test_num = 1; - -typedef process_cpu_clock clock_type; -typedef clock_type::duration dur; - -template -void benchmark(T & test_runner, std::string const& name) -{ - try { - 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_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_runner.threads_ ? "threaded -> ": "") - << name << "\n"; - } - else - { - process_cpu_clock::time_point start; - dur elapsed; - if (test_runner.threads_ > 0) - { - typedef std::vector > thread_group; - typedef thread_group::value_type value_type; - thread_group tg; - for (unsigned i=0;ijoinable()) t->join();}); - elapsed = process_cpu_clock::now() - start; - } - else - { - start = process_cpu_clock::now(); - test_runner(); - elapsed = process_cpu_clock::now() - start; - } - std::clog << test_num << ") " << (test_runner.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; -} - -bool compare_images(std::string const& src_fn,std::string const& dest_fn) -{ - std::unique_ptr reader1(mapnik::get_image_reader(dest_fn,"png")); - if (!reader1.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + dest_fn); - } - std::shared_ptr image_ptr1 = std::make_shared(reader1->width(),reader1->height()); - reader1->read(0,0,image_ptr1->data()); - - std::unique_ptr reader2(mapnik::get_image_reader(src_fn,"png")); - if (!reader2.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + src_fn); - } - std::shared_ptr image_ptr2 = std::make_shared(reader2->width(),reader2->height()); - reader2->read(0,0,image_ptr2->data()); - - image_data_32 const& dest = image_ptr1->data(); - image_data_32 const& src = image_ptr2->data(); - - unsigned int width = src.width(); - unsigned int height = src.height(); - if ((width != dest.width()) || height != dest.height()) return false; - for (unsigned int y = 0; y < height; ++y) - { - const unsigned int* row_from = src.getRow(y); - const unsigned int* row_to = dest.getRow(y); - for (unsigned int x = 0; x < width; ++x) - { - if (row_from[x] != row_to[x]) return false; - } - } - return true; -} - -struct test1 -{ - unsigned iter_; - unsigned threads_; - explicit test1(unsigned iterations, unsigned threads=0) : - iter_(iterations), - threads_(threads) - {} - - bool validate() - { - return true; - } - - void operator()() - { - mapnik::image_data_32 im(256,256); - std::string out; - for (unsigned i=0;i im_; - explicit test2(unsigned iterations, unsigned threads=0) : - iter_(iterations), - threads_(threads), - im_() - { - std::string filename("./benchmark/data/multicolor.png"); - std::unique_ptr reader(mapnik::get_image_reader(filename,"png")); - if (!reader.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + filename); - } - im_ = std::make_shared(reader->width(),reader->height()); - reader->read(0,0,im_->data()); - } - - bool validate() - { - std::string expected("./benchmark/data/multicolor-hextree-expected.png"); - std::string actual("./benchmark/data/multicolor-hextree-actual.png"); - mapnik::save_to_file(im_->data(),actual, "png8:m=h"); - return compare_images(actual,expected); - } - - void operator()() - { - std::string out; - for (unsigned i=0;idata(),"png8:m=h"); - } - } -}; - - -struct test3 -{ - unsigned iter_; - unsigned threads_; - double val_; - explicit test3(unsigned iterations, unsigned threads=0) : - iter_(iterations), - threads_(threads), - val_(-0.123) {} - bool validate() - { - std::ostringstream s; - s << val_; - return (s.str() == "-0.123"); - } - void operator()() - { - std::string out; - for (unsigned i=0;i(snprintf(&s[0], s.size()+1, "%g", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); - } - return true; - } - void operator()() - { - std::string out; - for (unsigned i=0;i -#include -#include - -struct test6 -{ - unsigned iter_; - unsigned threads_; - std::string src_; - std::string dest_; - mapnik::box2d from_; - mapnik::box2d to_; - bool defer_proj4_init_; - explicit test6(unsigned iterations, - unsigned threads, - std::string const& src, - std::string const& dest, - mapnik::box2d from, - mapnik::box2d to, - bool defer_proj) : - iter_(iterations), - threads_(threads), - src_(src), - dest_(dest), - from_(from), - to_(to), - defer_proj4_init_(defer_proj) {} - - bool validate() - { - mapnik::projection src(src_,defer_proj4_init_); - mapnik::projection dest(dest_,defer_proj4_init_); - mapnik::proj_transform tr(src,dest); - mapnik::box2d bbox = from_; - if (!tr.forward(bbox)) return false; - return ((std::fabs(bbox.minx() - to_.minx()) < .5) && - (std::fabs(bbox.maxx() - to_.maxx()) < .5) && - (std::fabs(bbox.miny() - to_.miny()) < .5) && - (std::fabs(bbox.maxy() - to_.maxy()) < .5) - ); - } - void operator()() - { - unsigned count=0; - for (int i=-180;i<180;++i) - { - for (int j=-85;j<85;++j) - { - mapnik::projection src(src_,defer_proj4_init_); - mapnik::projection dest(dest_,defer_proj4_init_); - mapnik::proj_transform tr(src,dest); - mapnik::box2d box(i,j,i,j); - if (!tr.forward(box)) throw std::runtime_error("could not transform coords"); - ++count; - } - } - } -}; - -#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 (unsigned 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() - { - transcoder tr("utf-8"); - mapnik::expression_grammar expr_grammar(tr); - mapnik::expression_ptr expr = mapnik::parse_expression(expr_,expr_grammar); - return mapnik::to_expression_string(*expr) == expr_; - } - void operator()() - { - transcoder tr("utf-8"); - mapnik::expression_grammar expr_grammar(tr); - for (unsigned i=0;i -#include -#include - -#include "agg_conv_clip_polygon.h" - -struct test11a -{ - unsigned iter_; - unsigned threads_; - std::string wkt_in_; - mapnik::box2d extent_; - typedef agg::conv_clip_polygon conv_clip; - test11a(unsigned iterations, - unsigned threads, - std::string wkt_in, - mapnik::box2d const& extent) - : iter_(iterations), - threads_(threads), - wkt_in_(wkt_in), - extent_(extent) { - - } - - bool validate() - { - std::string expected_wkt("Polygon((181 286.666667,233 454,315 340,421 446,463 324,559 466,631 321.320755,631 234.386861,528 178,394 229,329 138,212 134,183 228,200 264,181 238.244444),(313 190,440 256,470 248,510 305,533 237,613 263,553 397,455 262,405 378,343 287,249 334,229 191,313 190,313 190))"); - boost::ptr_vector paths; - if (!mapnik::from_wkt(wkt_in_, paths)) - { - throw std::runtime_error("Failed to parse WKT"); - } - for (geometry_type & geom : paths) - { - conv_clip clipped(geom); - clipped.clip_box( - extent_.minx(), - extent_.miny(), - extent_.maxx(), - extent_.maxy()); - unsigned cmd; - double x,y; - mapnik::geometry_type geom2(mapnik::geometry_type::types::Polygon); - while ((cmd = clipped.vertex(&x, &y)) != SEG_END) { - geom2.push_vertex(x,y,(mapnik::CommandType)cmd); - } - std::string wkt; - bool result = mapnik::util::to_wkt(wkt,geom2); - if (result) { - return (wkt == expected_wkt); - } - } - return false; - } - 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 extent_; - typedef agg::conv_clipper poly_clipper; - 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() - { - std::string expected_wkt("Polygon((212 134,329 138,394 229,528 178,631 234.4,631 321.3,559 466,463 324,421 446,315 340,233 454,181 286.7,181 238.2,200 264,183 228),(313 190,229 191,249 334,343 287,405 378,455 262,553 397,613 263,533 237,510 305,470 248,440 256))"); - 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()); - ps.line_to(extent_.maxx(), extent_.maxy()); - ps.line_to(extent_.maxx(), extent_.miny()); - ps.close_polygon(); - for (geometry_type & geom : paths) - { - poly_clipper clipped(geom,ps, - agg::clipper_and, - agg::clipper_non_zero, - agg::clipper_non_zero, - 1); - clipped.rewind(0); - unsigned cmd; - double x,y; - mapnik::geometry_type geom2(mapnik::geometry_type::types::Polygon); - while ((cmd = clipped.vertex(&x, &y)) != SEG_END) { - geom2.push_vertex(x,y,(mapnik::CommandType)cmd); - } - std::string wkt; - bool result = mapnik::util::to_wkt(wkt,geom2); - if (result) { - return (wkt == expected_wkt); - } - } - return false; - } - 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()); - ps.line_to(extent_.maxx(), extent_.maxy()); - 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() - { - std::string expected_wkt("Polygon((181 286.666667,233 454,315 340,421 446,463 324,559 466,631 321.320755,631 234.386861,528 178,394 229,329 138,212 134,183 228,200 264,181 238.244444,181 286.666667),(313 190,440 256,470 248,510 305,533 237,613 263,553 397,455 262,405 378,343 287,249 334,229 191,313 190))"); - boost::ptr_vector paths; - if (!mapnik::from_wkt(wkt_in_, paths)) - { - throw std::runtime_error("Failed to parse WKT"); - } - for ( geometry_type & geom : paths) - { - poly_clipper clipped(extent_, geom); - unsigned cmd; - double x,y; - mapnik::geometry_type geom2(mapnik::geometry_type::types::Polygon); - while ((cmd = clipped.vertex(&x, &y)) != SEG_END) { - geom2.push_vertex(x,y,(mapnik::CommandType)cmd); - } - std::string wkt; - bool result = mapnik::util::to_wkt(wkt,geom2); - if (result) { - return (wkt == expected_wkt); - } - } - return false; - } - 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 -#include -struct test13 -{ - unsigned iter_; - unsigned threads_; - - test13(unsigned iterations, - unsigned threads) - : iter_(iterations), - threads_(threads) - {} - - bool validate() - { - return true; - } - - void operator()() - { - mapnik::freetype_engine engine; - unsigned long count = 0; - for (unsigned i=0;i -#include -#include -#include - -struct test14 -{ - unsigned iter_; - unsigned threads_; - std::string xml_; - mapnik::box2d extent_; - test14(unsigned iterations, - unsigned threads, - std::string const& xml, - mapnik::box2d const& extent) - : iter_(iterations), - threads_(threads), - xml_(xml), - extent_(extent) - {} - - bool validate() - { - mapnik::Map m(256,256); - mapnik::load_map(m,xml_); - m.zoom_to_box(extent_); - mapnik::image_32 im(m.width(),m.height()); - mapnik::agg_renderer ren(m,im); - ren.apply(); - //mapnik::save_to_file(im,"test.png"); - return true; - } - - void operator()() - { - mapnik::Map m(256,256); - mapnik::load_map(m,xml_); - m.zoom_to_box(extent_); - for (unsigned i=0;i ren(m,im); - ren.apply(); - } - } -}; - -int main( int argc, char** argv) -{ - if (argc > 0) { - for (int i=0;i(arg)); - } - } - } - } - mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); - try - { - std::cout << "starting benchmark…\n"; - - { - test1 runner(100); - benchmark(runner,"encoding blank image as png"); - } - - { - test2 runner(100); - benchmark(runner,"encoding multicolor image as png8:m=h"); - } - - { - test1 runner(10,10); - benchmark(runner,"encoding blank image as png"); - } - - { - test2 runner(10,10); - benchmark(runner,"encoding multicolor image as png8:m=h"); - } - - { - test3 runner(1000000); - benchmark(runner,"double to string conversion with std::ostringstream"); - } - - { - test4 runner(1000000); - benchmark(runner,"double to string conversion with mapnik::util_to_string"); - } - - { - test5 runner(1000000); - benchmark(runner,"double to string conversion with snprintf"); - } - - { - test3 runner(100000,10); - benchmark(runner,"double to string conversion with std::ostringstream"); - } - - { - test4 runner(100000,10); - benchmark(runner,"double to string conversion with mapnik::util_to_string"); - } - - { - test5 runner(100000,10); - benchmark(runner,"double to string conversion with snprintf"); - } - - mapnik::box2d from(-180,-80,180,80); - mapnik::box2d to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316); - - { - // 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,true); - benchmark(runner,"lonlat -> merc coord transformation (epsg)"); - } - - { - test6 runner(100000000,100, - "+init=epsg:3857", - "+init=epsg:4326", - to,from,true); - benchmark(runner,"merc -> lonlat coord transformation (epsg)"); - } - - { - 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,true); - benchmark(runner,"merc -> 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"); - } - - // TODO - consider bring back rule cache benchmarks after c++11 is in master - // previously test 9/10 - - // polygon/rect clipping - // IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190)) - // RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) - // OUT (expected) - // POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190)) - - mapnik::box2d clipping_box(181,106,631,470); - - { - 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()) ); - test11a runner(10000,10,wkt_in,clipping_box); - benchmark(runner,"clipping polygon with conv_clip_polygon"); - } - - { - 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()) ); - test11 runner(10000,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()) ); - test12 runner(10000,10,wkt_in,clipping_box); - benchmark(runner,"clipping polygon with mapnik::polygon_clipper"); - } - - { - bool success = mapnik::freetype_engine::register_fonts("./fonts", true); - if (!success) { - std::clog << "warning, did not register any new fonts!\n"; - } - std::size_t face_count = mapnik::freetype_engine::face_names().size(); - test13 runner(1000,10); - benchmark(runner, (boost::format("font_engine: created %ld faces in ") % (face_count * 1000 * 10)).str()); - } - - { - test14 runner(500,10, - "benchmark/data/polygon_rendering_clip.xml", - mapnik::box2d(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298)); - benchmark(runner, "rendering polygon with clipping at full extent"); - } - - { - test14 runner(500,10, - "benchmark/data/polygon_rendering_no_clip.xml", - mapnik::box2d(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298)); - benchmark(runner, "rendering polygon without clipping at full extent"); - } - - { - // note: bbox below is for 16/10491/22911.png - test14 runner(500,10, - "benchmark/data/polygon_rendering_clip.xml", - mapnik::box2d(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214)); - benchmark(runner, "rendering polygon with clipping at z16 extent"); - } - - { - test14 runner(500,10, - "benchmark/data/polygon_rendering_no_clip.xml", - mapnik::box2d(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214)); - benchmark(runner, "rendering polygon without clipping at z16 extent"); - } - - std::cout << "...benchmark done\n"; - return 0; - } - catch (std::exception const& ex) - { - std::clog << "test error: " << ex.what() << "\n"; - return -1; - } -} diff --git a/benchmark/template.cpp b/benchmark/template.cpp new file mode 100644 index 000000000..a91ecb36a --- /dev/null +++ b/benchmark/template.cpp @@ -0,0 +1,17 @@ +#include "bench_framework.hpp" + +class test : public benchmark::test_case +{ +public: + test(mapnik::parameters const& params) + : test_case(params) {} + bool validate() const + { + return true; + } + void operator()() const + { + } +}; + +BENCHMARK(test,"test name") diff --git a/benchmark/test_expression_parse.cpp b/benchmark/test_expression_parse.cpp new file mode 100644 index 000000000..536e7566e --- /dev/null +++ b/benchmark/test_expression_parse.cpp @@ -0,0 +1,59 @@ +#include "bench_framework.hpp" +#include +#include +#include +#include + +class test : public benchmark::test_case +{ + std::string expr_; +public: + test(mapnik::parameters const& params) + : test_case(params), + expr_("([foo]=1)") {} + bool validate() const + { + mapnik::expression_ptr expr = mapnik::parse_expression(expr_,"utf-8"); + return mapnik::to_expression_string(*expr) == expr_; + } + void operator()() const + { + for (std::size_t i=0;i expr_grammar(tr); + mapnik::expression_ptr expr = mapnik::parse_expression(expr_,expr_grammar); + return mapnik::to_expression_string(*expr) == expr_; + } + void operator()() const + { + mapnik::transcoder tr("utf-8"); + mapnik::expression_grammar expr_grammar(tr); + for (std::size_t i=0;i +#include + +class test : public benchmark::test_case +{ + mapnik::image_data_32 im_; +public: + test(mapnik::parameters const& params) + : test_case(params), + im_(256,256) {} + bool validate() const + { + return true; + } + void operator()() const + { + std::string out; + for (std::size_t i=0;i im_; +public: + test(mapnik::parameters const& params) + : test_case(params) { + std::string filename("./benchmark/data/multicolor.png"); + std::unique_ptr reader(mapnik::get_image_reader(filename,"png")); + if (!reader.get()) + { + throw mapnik::image_reader_exception("Failed to load: " + filename); + } + im_ = std::make_shared(reader->width(),reader->height()); + reader->read(0,0,im_->data()); + } + bool validate() const + { + std::string expected("./benchmark/data/multicolor-hextree-expected.png"); + std::string actual("./benchmark/data/multicolor-hextree-actual.png"); + mapnik::save_to_file(im_->data(),actual, "png8:m=h"); + return benchmark::compare_images(actual,expected); + } + void operator()() const + { + std::string out; + for (std::size_t i=0;idata(),"png8:m=h"); + } + } +}; + +BENCHMARK(test,"encoding multicolor png") diff --git a/benchmark/test_proj_transform1.cpp b/benchmark/test_proj_transform1.cpp new file mode 100644 index 000000000..7ddb270ba --- /dev/null +++ b/benchmark/test_proj_transform1.cpp @@ -0,0 +1,96 @@ +#include "bench_framework.hpp" +#include +#include +#include + +class test : public benchmark::test_case +{ + std::string src_; + std::string dest_; + mapnik::box2d from_; + mapnik::box2d to_; + bool defer_proj4_init_; +public: + test(mapnik::parameters const& params, + std::string const& src, + std::string const& dest, + mapnik::box2d const& from, + mapnik::box2d const& to, + bool defer_proj) + : test_case(params), + src_(src), + dest_(dest), + from_(from), + to_(to), + defer_proj4_init_(defer_proj) {} + bool validate() const + { + mapnik::projection src(src_,defer_proj4_init_); + mapnik::projection dest(dest_,defer_proj4_init_); + mapnik::proj_transform tr(src,dest); + mapnik::box2d bbox = from_; + if (!tr.forward(bbox)) return false; + return ((std::fabs(bbox.minx() - to_.minx()) < .5) && + (std::fabs(bbox.maxx() - to_.maxx()) < .5) && + (std::fabs(bbox.miny() - to_.miny()) < .5) && + (std::fabs(bbox.maxy() - to_.maxy()) < .5) + ); + } + void operator()() const + { + for (std::size_t i=0;i box(i,j,i,j); + if (!tr.forward(box)) throw std::runtime_error("could not transform coords"); + } + } + } + } +}; + +// 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"); + test test_runner(params, + from_str, + to_str, + from, + to, + true); + run(test_runner,"lonlat -> merc coord transformation (epsg)"); + test test_runner2(params, + from_str2, + to_str2, + from, + to, + true); + run(test_runner2,"lonlat -> merc coord transformation (literal)"); + test test_runner3(params, + to_str, + from_str, + to, + from, + true); + run(test_runner3,"merc -> lonlat coord transformation (epsg)"); + test test_runner4(params, + to_str2, + from_str2, + to, + from, + true); + return run(test_runner4,"merc -> lonlat coord transformation (literal)"); +} diff --git a/benchmark/test_to_string1.cpp b/benchmark/test_to_string1.cpp new file mode 100644 index 000000000..f9158f107 --- /dev/null +++ b/benchmark/test_to_string1.cpp @@ -0,0 +1,27 @@ +#include "bench_framework.hpp" +#include + +class test : public benchmark::test_case +{ + double value_; +public: + test(mapnik::parameters const& params) + : test_case(params), + value_(-0.1234) {} + bool validate() const + { + std::string s; + mapnik::util::to_string(s,value_); + return (s == "-0.1234"); + } + void operator()() const + { + std::string out; + for (std::size_t i=0;istring") diff --git a/benchmark/test_to_string2.cpp b/benchmark/test_to_string2.cpp new file mode 100644 index 000000000..b7e5655a0 --- /dev/null +++ b/benchmark/test_to_string2.cpp @@ -0,0 +1,28 @@ +#include "bench_framework.hpp" +#include + +class test : public benchmark::test_case +{ + double value_; +public: + test(mapnik::parameters const& params) + : test_case(params), + value_(-0.1234) {} + bool validate() const + { + std::ostringstream s; + s << value_; + return (s.str() == "-0.1234"); + } + void operator()() const + { + std::string out; + for (std::size_t i=0;istring") diff --git a/include/mapnik/datasource_cache.hpp b/include/mapnik/datasource_cache.hpp index 5e1fbc72e..a5f16236f 100644 --- a/include/mapnik/datasource_cache.hpp +++ b/include/mapnik/datasource_cache.hpp @@ -24,6 +24,7 @@ #define MAPNIK_DATASOURCE_CACHE_HPP // mapnik +#include #include #include #include