-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_boost_geometry_wkt.cpp
More file actions
153 lines (132 loc) · 4.32 KB
/
benchmark_boost_geometry_wkt.cpp
File metadata and controls
153 lines (132 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#define CELERO_STATIC
#include <cmath>
#include <random>
#include <sstream>
#include <string>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/lexical_cast.hpp>
#include <celero/Celero.h>
#include "benchmark.hpp"
#ifdef NDEBUG
enum { bg_samples = 30, bg_iterations = 0 };
#else
enum { bg_samples = 1, bg_iterations = 1 };
#endif
// Uncomment to enable boost::geometry::to_wkt from https://github.com/boostorg/geometry/pull/670
#define BOOST_GEOMETRY_PR670
namespace boost { namespace geometry {
template <typename Geometry>
inline std::string to_wkt_wrapper(Geometry const& geometry)
{
std::stringstream ss;
ss << boost::geometry::wkt(geometry);
return ss.str();
}
template <typename Geometry>
inline std::string to_wkt_wrapper(Geometry const& geometry, int significant_digits)
{
std::stringstream ss;
ss.precision(significant_digits);
ss << boost::geometry::wkt(geometry);
return ss.str();
}
}}
struct Fixture : celero::TestFixture
{
using point_t = boost::geometry::model::d2::point_xy<double>;
boost::geometry::model::multi_point<point_t> multi_point_;
std::vector<point_t> points_;
std::vector<celero::TestFixture::ExperimentValue> getExperimentValues() const override
{
std::uint64_t const total_tests = 4;
// Problem space as number of points (pairs of X/Y)
std::vector<celero::TestFixture::ExperimentValue> v;
v.emplace_back(1, uint64_t(std::pow(2, 0)));
v.emplace_back(256, uint64_t(std::pow(2, total_tests - 0)));
v.emplace_back(512, uint64_t(std::pow(2, total_tests - 1)));
v.emplace_back(1024, uint64_t(std::pow(2, total_tests - 2)));
return v;
}
void setUp(celero::TestFixture::ExperimentValue const& e) override
{
std::random_device rd;
std::mt19937 g(rd());
std::uniform_real_distribution<> d(-180.0, 180.0);
auto const size = static_cast<std::size_t>(e.Value);
this->points_.reserve(size);
for (std::size_t i = 0; i < size; i++)
{
auto const x = d(g);
auto const y = d(g);
boost::geometry::append(this->multi_point_, boost::geometry::make<point_t>(x, y));
this->points_.emplace_back(x, y);
}
}
void tearDown() override
{
multi_point_ = {};
points_ = {};
}
};
CELERO_MAIN
BASELINE_F(wkt, to_string, Fixture, bg_samples, bg_iterations)
{
for (auto const& p : this->points_)
{
celero::DoNotOptimizeAway(std::to_string(p.x()));
celero::DoNotOptimizeAway(std::to_string(p.y()));
}
}
BENCHMARK_F(wkt, stringstream, Fixture, bg_samples, bg_iterations)
{
std::ostringstream oss;
for (auto const& p : this->points_)
{
celero::DoNotOptimizeAway(oss << p.x());
celero::DoNotOptimizeAway(oss << p.y());
}
celero::DoNotOptimizeAway(oss.str());
}
BENCHMARK_F(wkt, lexical_cast, Fixture, bg_samples, bg_iterations)
{
std::ostringstream oss;
for (auto const& p : this->points_)
{
celero::DoNotOptimizeAway(boost::lexical_cast<std::string>(p.x()));
celero::DoNotOptimizeAway(boost::lexical_cast<std::string>(p.y()));
}
celero::DoNotOptimizeAway(oss.str());
}
BENCHMARK_F(wkt, wkt, Fixture, bg_samples, bg_iterations)
{
std::ostringstream oss;
celero::DoNotOptimizeAway(oss << boost::geometry::wkt(this->multi_point_));
celero::DoNotOptimizeAway(oss.str());
}
BENCHMARK_F(wkt, to_wkt_wrap, Fixture, bg_samples, bg_iterations)
{
celero::DoNotOptimizeAway(boost::geometry::to_wkt_wrapper(this->multi_point_));
}
BENCHMARK_F(wkt, to_wkt_wrap_3dig, Fixture, bg_samples, bg_iterations)
{
celero::DoNotOptimizeAway(boost::geometry::to_wkt_wrapper(this->multi_point_, 3));
}
BENCHMARK_F(wkt, to_wkt_wrap_9dig, Fixture, bg_samples, bg_iterations)
{
celero::DoNotOptimizeAway(boost::geometry::to_wkt_wrapper(this->multi_point_, 9));
}
#ifdef BOOST_GEOMETRY_PR670
BENCHMARK_F(wkt, to_wkt, Fixture, bg_samples, bg_iterations)
{
celero::DoNotOptimizeAway(boost::geometry::to_wkt(this->multi_point_));
}
BENCHMARK_F(wkt, to_wkt_3dig, Fixture, bg_samples, bg_iterations)
{
celero::DoNotOptimizeAway(boost::geometry::to_wkt(this->multi_point_, 3));
}
BENCHMARK_F(wkt, to_wkt_9dig, Fixture, bg_samples, bg_iterations)
{
celero::DoNotOptimizeAway(boost::geometry::to_wkt(this->multi_point_, 9));
}
#endif