From 19526eb7f76c74df5beb87be3b08977220a79095 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 27 Jan 2013 17:26:32 -0800 Subject: [PATCH] benchmark: add tests for longlat/merc transformations --- benchmark/run.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/benchmark/run.cpp b/benchmark/run.cpp index 5c25f40c9..c09029378 100644 --- a/benchmark/run.cpp +++ b/benchmark/run.cpp @@ -269,6 +269,64 @@ struct test5 }; +#include +#include +#include +#include + +struct test6 +{ + unsigned iter_; + unsigned threads_; + std::string src_; + std::string dest_; + mapnik::box2d from_; + mapnik::box2d to_; + explicit test6(unsigned iterations, + unsigned threads, + std::string const& src, + std::string const& dest, + mapnik::box2d from, + mapnik::box2d to) : + iter_(iterations), + threads_(threads), + src_(src), + dest_(dest), + from_(from), + to_(to) {} + + bool validate() + { + mapnik::projection src(src_); + mapnik::projection dest(dest_); + 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()() + { + mapnik::projection src(src_); + mapnik::projection dest(dest_); + mapnik::proj_transform tr(src,dest); + unsigned count=0; + for (int i=-180;i<180;i=++i) + { + for (int j=-85;j<85;++j) + { + mapnik::box2d box(i,j,i,j); + if (!tr.forward(box)) throw std::runtime_error("could not transform coords"); + ++count; + } + } + } +}; + + int main( int argc, char** argv) { if (argc > 0) { @@ -338,6 +396,41 @@ int main( int argc, char** argv) 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); + benchmark(runner,"lonlat -> merc coord transformation (epsg)"); + } + + { + test6 runner(100000000,100, + "+init=epsg:3857", + "+init=epsg:4326", + to,from); + 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); + 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); + benchmark(runner,"merc -> lonlat coord transformation (literal)"); + } + std::cout << "...benchmark done\n"; return 0; }