From 3932cc51b37035bee88e118251d7503f6d4f9435 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 1 Oct 2015 14:47:55 -0700 Subject: [PATCH] add getline benchmark - refs #3101 --- benchmark/build.py | 1 + benchmark/test_getline.cpp | 123 ++++++++++++++++++++++++++++++++ plugins/input/csv/csv_utils.hpp | 2 +- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 benchmark/test_getline.cpp diff --git a/benchmark/build.py b/benchmark/build.py index 800a9abb5..37ba86707 100644 --- a/benchmark/build.py +++ b/benchmark/build.py @@ -47,6 +47,7 @@ benchmarks = [ "test_marker_cache.cpp", "test_quad_tree.cpp", "test_noop_rendering.cpp", + "test_getline.cpp", # "test_numeric_cast_vs_static_cast.cpp", ] for cpp_test in benchmarks: diff --git a/benchmark/test_getline.cpp b/benchmark/test_getline.cpp new file mode 100644 index 000000000..c4c609a61 --- /dev/null +++ b/benchmark/test_getline.cpp @@ -0,0 +1,123 @@ +#include "bench_framework.hpp" +#include +#include +#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 line_data = params.get("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 line_data = params.get("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 extract_geometry(std::vector const& row, geometry_column_locator const& locator) +static inline mapnik::geometry::geometry extract_geometry(std::vector const& row, geometry_column_locator const& locator) { mapnik::geometry::geometry geom; if (locator.type == geometry_column_locator::WKT)