Skip to content

Commit 3932cc5

Browse files
author
Dane Springmeyer
committed
add getline benchmark - refs mapnik#3101
1 parent 530416f commit 3932cc5

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

benchmark/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"test_marker_cache.cpp",
4848
"test_quad_tree.cpp",
4949
"test_noop_rendering.cpp",
50+
"test_getline.cpp",
5051
# "test_numeric_cast_vs_static_cast.cpp",
5152
]
5253
for cpp_test in benchmarks:

benchmark/test_getline.cpp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include "bench_framework.hpp"
2+
#include <cstring>
3+
#include <cstdlib>
4+
#include "../plugins/input/csv/csv_utils.hpp"
5+
6+
class test : public benchmark::test_case
7+
{
8+
public:
9+
std::string line_data_;
10+
test(mapnik::parameters const& params)
11+
: test_case(params)
12+
{
13+
boost::optional<std::string> line_data = params.get<std::string>("line");
14+
if (!line_data)
15+
{
16+
throw std::runtime_error("please provide a --line \"one line\ntwo line\"");
17+
}
18+
line_data_ = *line_data;
19+
}
20+
21+
bool validate() const
22+
{
23+
std::string first = line_data_.substr(line_data_.find_first_not_of('\n'));
24+
char newline = '\n';
25+
std::string csv_line;
26+
std::stringstream s;
27+
s << line_data_;
28+
std::getline(s,csv_line,s.widen(newline));
29+
if (csv_line != first)
30+
{
31+
return true;
32+
}
33+
else
34+
{
35+
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
36+
}
37+
return true;
38+
}
39+
bool operator()() const
40+
{
41+
char newline = '\n';
42+
std::string csv_line;
43+
std::stringstream s;
44+
s << line_data_;
45+
for (unsigned i=0;i<iterations_;++i)
46+
{
47+
std::getline(s,csv_line,s.widen(newline));
48+
}
49+
return true;
50+
}
51+
};
52+
53+
54+
class test2 : public benchmark::test_case
55+
{
56+
public:
57+
std::string line_data_;
58+
test2(mapnik::parameters const& params)
59+
: test_case(params)
60+
{
61+
boost::optional<std::string> line_data = params.get<std::string>("line");
62+
if (!line_data)
63+
{
64+
throw std::runtime_error("please provide a --line \"one line\ntwo line\"");
65+
}
66+
line_data_ = *line_data;
67+
}
68+
69+
bool validate() const
70+
{
71+
std::string first = line_data_.substr(line_data_.find_first_not_of('\n'));
72+
char newline = '\n';
73+
std::string csv_line;
74+
std::stringstream s;
75+
s << line_data_;
76+
csv_utils::getline_csv(s,csv_line,s.widen(newline));
77+
if (csv_line != first)
78+
{
79+
return true;
80+
}
81+
else
82+
{
83+
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
84+
}
85+
return true;
86+
}
87+
bool operator()() const
88+
{
89+
char newline = '\n';
90+
std::string csv_line;
91+
std::stringstream s;
92+
s << line_data_;
93+
for (unsigned i=0;i<iterations_;++i)
94+
{
95+
csv_utils::getline_csv(s,csv_line,s.widen(newline));
96+
}
97+
return true;
98+
}
99+
};
100+
101+
int main(int argc, char** argv)
102+
{
103+
int return_value = 0;
104+
try
105+
{
106+
mapnik::parameters params;
107+
benchmark::handle_args(argc,argv,params);
108+
{
109+
test test_runner(params);
110+
return_value = return_value | run(test_runner,"std::getline");
111+
}
112+
{
113+
test2 test_runner2(params);
114+
return_value = return_value | run(test_runner2,"csv_utils::getline_csv");
115+
}
116+
}
117+
catch (std::exception const& ex)
118+
{
119+
std::clog << ex.what() << "\n";
120+
return -1;
121+
}
122+
return return_value;
123+
}

plugins/input/csv/csv_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static inline void locate_geometry_column(std::string const& header, std::size_t
244244
}
245245
}
246246

247-
static mapnik::geometry::geometry<double> extract_geometry(std::vector<std::string> const& row, geometry_column_locator const& locator)
247+
static inline mapnik::geometry::geometry<double> extract_geometry(std::vector<std::string> const& row, geometry_column_locator const& locator)
248248
{
249249
mapnik::geometry::geometry<double> geom;
250250
if (locator.type == geometry_column_locator::WKT)

0 commit comments

Comments
 (0)