add getline benchmark - refs #3101

This commit is contained in:
Dane Springmeyer 2015-10-01 14:47:55 -07:00
parent 530416f0aa
commit 3932cc51b3
3 changed files with 125 additions and 1 deletions

View file

@ -47,6 +47,7 @@ benchmarks = [
"test_marker_cache.cpp", "test_marker_cache.cpp",
"test_quad_tree.cpp", "test_quad_tree.cpp",
"test_noop_rendering.cpp", "test_noop_rendering.cpp",
"test_getline.cpp",
# "test_numeric_cast_vs_static_cast.cpp", # "test_numeric_cast_vs_static_cast.cpp",
] ]
for cpp_test in benchmarks: for cpp_test in benchmarks:

123
benchmark/test_getline.cpp Normal file
View file

@ -0,0 +1,123 @@
#include "bench_framework.hpp"
#include <cstring>
#include <cstdlib>
#include "../plugins/input/csv/csv_utils.hpp"
class test : public benchmark::test_case
{
public:
std::string line_data_;
test(mapnik::parameters const& params)
: test_case(params)
{
boost::optional<std::string> line_data = params.get<std::string>("line");
if (!line_data)
{
throw std::runtime_error("please provide a --line \"one line\ntwo line\"");
}
line_data_ = *line_data;
}
bool validate() const
{
std::string first = line_data_.substr(line_data_.find_first_not_of('\n'));
char newline = '\n';
std::string csv_line;
std::stringstream s;
s << line_data_;
std::getline(s,csv_line,s.widen(newline));
if (csv_line != first)
{
return true;
}
else
{
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";
}
return true;
}
bool operator()() const
{
char newline = '\n';
std::string csv_line;
std::stringstream s;
s << line_data_;
for (unsigned i=0;i<iterations_;++i)
{
std::getline(s,csv_line,s.widen(newline));
}
return true;
}
};
class test2 : public benchmark::test_case
{
public:
std::string line_data_;
test2(mapnik::parameters const& params)
: test_case(params)
{
boost::optional<std::string> line_data = params.get<std::string>("line");
if (!line_data)
{
throw std::runtime_error("please provide a --line \"one line\ntwo line\"");
}
line_data_ = *line_data;
}
bool validate() const
{
std::string first = line_data_.substr(line_data_.find_first_not_of('\n'));
char newline = '\n';
std::string csv_line;
std::stringstream s;
s << line_data_;
csv_utils::getline_csv(s,csv_line,s.widen(newline));
if (csv_line != first)
{
return true;
}
else
{
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";
}
return true;
}
bool operator()() const
{
char newline = '\n';
std::string csv_line;
std::stringstream s;
s << line_data_;
for (unsigned i=0;i<iterations_;++i)
{
csv_utils::getline_csv(s,csv_line,s.widen(newline));
}
return true;
}
};
int main(int argc, char** argv)
{
int return_value = 0;
try
{
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
{
test test_runner(params);
return_value = return_value | run(test_runner,"std::getline");
}
{
test2 test_runner2(params);
return_value = return_value | run(test_runner2,"csv_utils::getline_csv");
}
}
catch (std::exception const& ex)
{
std::clog << ex.what() << "\n";
return -1;
}
return return_value;
}

View file

@ -244,7 +244,7 @@ static inline void locate_geometry_column(std::string const& header, std::size_t
} }
} }
static mapnik::geometry::geometry<double> extract_geometry(std::vector<std::string> const& row, geometry_column_locator const& locator) static inline mapnik::geometry::geometry<double> extract_geometry(std::vector<std::string> const& row, geometry_column_locator const& locator)
{ {
mapnik::geometry::geometry<double> geom; mapnik::geometry::geometry<double> geom;
if (locator.type == geometry_column_locator::WKT) if (locator.type == geometry_column_locator::WKT)