Re-use proj_transform as creating a new one is extremely expensive on libproj >= 6 (NOTE: epsg:4326 and epsg:3857 are special cases which use internal implementations and are not expensive to create on stack).

This commit is contained in:
Artem Pavlenko 2021-03-18 15:32:13 +00:00
parent 199e609a79
commit 9c7e21fa47

View file

@ -9,7 +9,7 @@ class test : public benchmark::test_case
std::string dest_; std::string dest_;
mapnik::box2d<double> from_; mapnik::box2d<double> from_;
mapnik::box2d<double> to_; mapnik::box2d<double> to_;
bool defer_proj4_init_; bool defer_proj_init_;
public: public:
test(mapnik::parameters const& params, test(mapnik::parameters const& params,
std::string const& src, std::string const& src,
@ -22,11 +22,11 @@ public:
dest_(dest), dest_(dest),
from_(from), from_(from),
to_(to), to_(to),
defer_proj4_init_(defer_proj) {} defer_proj_init_(defer_proj) {}
bool validate() const bool validate() const
{ {
mapnik::projection src(src_,defer_proj4_init_); mapnik::projection src(src_,defer_proj_init_);
mapnik::projection dest(dest_,defer_proj4_init_); mapnik::projection dest(dest_,defer_proj_init_);
mapnik::proj_transform tr(src,dest); mapnik::proj_transform tr(src,dest);
mapnik::box2d<double> bbox = from_; mapnik::box2d<double> bbox = from_;
if (!tr.forward(bbox)) return false; if (!tr.forward(bbox)) return false;
@ -38,15 +38,15 @@ public:
} }
bool operator()() const bool operator()() const
{ {
mapnik::projection src(src_,defer_proj_init_);
mapnik::projection dest(dest_,defer_proj_init_);
mapnik::proj_transform tr(src,dest);
for (std::size_t i=0;i<iterations_;++i) for (std::size_t i=0;i<iterations_;++i)
{ {
for (int j=-180;j<180;j=j+5) for (int j=-180;j<180;j=j+5)
{ {
for (int k=-85;k<85;k=k+5) for (int k=-85;k<85;k=k+5)
{ {
mapnik::projection src(src_,defer_proj4_init_);
mapnik::projection dest(dest_,defer_proj4_init_);
mapnik::proj_transform tr(src,dest);
mapnik::box2d<double> box(j,k,j,k); mapnik::box2d<double> box(j,k,j,k);
if (!tr.forward(box)) throw std::runtime_error("could not transform coords"); if (!tr.forward(box)) throw std::runtime_error("could not transform coords");
} }