Merge remote-tracking branch 'origin/master'
Conflicts: plugins/input/csv/csv_datasource.cpp
This commit is contained in:
commit
1bccca9ff8
10 changed files with 148 additions and 22 deletions
|
@ -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:
|
||||||
|
|
|
@ -9,7 +9,7 @@ function run {
|
||||||
${BASE}/$1 --threads 0 --iterations $3;
|
${BASE}/$1 --threads 0 --iterations $3;
|
||||||
${BASE}/$1 --threads $2 --iterations $(expr $3 / $2);
|
${BASE}/$1 --threads $2 --iterations $(expr $3 / $2);
|
||||||
}
|
}
|
||||||
|
run test_getline 30 10000000
|
||||||
#run test_array_allocation 20 100000
|
#run test_array_allocation 20 100000
|
||||||
#run test_png_encoding1 10 1000
|
#run test_png_encoding1 10 1000
|
||||||
#run test_png_encoding2 10 50
|
#run test_png_encoding2 10 50
|
||||||
|
|
125
benchmark/test_getline.cpp
Normal file
125
benchmark/test_getline.cpp
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
#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),
|
||||||
|
line_data_("this is one line\nand this is a second line\nand a third line")
|
||||||
|
{
|
||||||
|
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||||
|
if (line_data)
|
||||||
|
{
|
||||||
|
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_;
|
||||||
|
auto newline_widened = s.widen(newline);
|
||||||
|
for (unsigned i=0;i<iterations_;++i)
|
||||||
|
{
|
||||||
|
std::getline(s,csv_line,newline_widened);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class test2 : public benchmark::test_case
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string line_data_;
|
||||||
|
test2(mapnik::parameters const& params)
|
||||||
|
: test_case(params),
|
||||||
|
line_data_("this is one line\nand this is a second line\nand a third line")
|
||||||
|
{
|
||||||
|
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||||
|
if (line_data)
|
||||||
|
{
|
||||||
|
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_;
|
||||||
|
auto newline_widened = s.widen(newline);
|
||||||
|
for (unsigned i=0;i<iterations_;++i)
|
||||||
|
{
|
||||||
|
csv_utils::getline_csv(s,csv_line,newline_widened);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ public:
|
||||||
boost::optional<std::string> map = params.get<std::string>("map");
|
boost::optional<std::string> map = params.get<std::string>("map");
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("please provide a --map=<path to xml> arg");
|
throw std::runtime_error("please provide a --map <path to xml> arg");
|
||||||
}
|
}
|
||||||
xml_ = *map;
|
xml_ = *map;
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ private:
|
||||||
/*!
|
/*!
|
||||||
* \brief render features list queued when they are available.
|
* \brief render features list queued when they are available.
|
||||||
*/
|
*/
|
||||||
void render_material(layer_rendering_material & mat, Processor & p );
|
void render_material(layer_rendering_material const & mat, Processor & p );
|
||||||
|
|
||||||
Map const& m_;
|
Map const& m_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -69,11 +69,10 @@ struct layer_rendering_material
|
||||||
lay_(lay),
|
lay_(lay),
|
||||||
proj0_(dest),
|
proj0_(dest),
|
||||||
proj1_(lay.srs(),true) {}
|
proj1_(lay.srs(),true) {}
|
||||||
|
|
||||||
|
layer_rendering_material(layer_rendering_material && rhs) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
using layer_rendering_material_ptr = std::shared_ptr<layer_rendering_material>;
|
|
||||||
|
|
||||||
|
|
||||||
template <typename Processor>
|
template <typename Processor>
|
||||||
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
|
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
|
||||||
: m_(m)
|
: m_(m)
|
||||||
|
@ -102,7 +101,7 @@ void feature_style_processor<Processor>::apply(double scale_denom)
|
||||||
// in a second time, we fetch the results and
|
// in a second time, we fetch the results and
|
||||||
// do the actual rendering
|
// do the actual rendering
|
||||||
|
|
||||||
std::vector<layer_rendering_material_ptr> mat_list;
|
std::vector<layer_rendering_material> mat_list;
|
||||||
|
|
||||||
// Define processing context map used by datasources
|
// Define processing context map used by datasources
|
||||||
// implementing asynchronous queries
|
// implementing asynchronous queries
|
||||||
|
@ -113,9 +112,9 @@ void feature_style_processor<Processor>::apply(double scale_denom)
|
||||||
if (lyr.visible(scale_denom))
|
if (lyr.visible(scale_denom))
|
||||||
{
|
{
|
||||||
std::set<std::string> names;
|
std::set<std::string> names;
|
||||||
layer_rendering_material_ptr mat = std::make_shared<layer_rendering_material>(lyr, proj);
|
layer_rendering_material mat(lyr, proj);
|
||||||
|
|
||||||
prepare_layer(*mat,
|
prepare_layer(mat,
|
||||||
ctx_map,
|
ctx_map,
|
||||||
p,
|
p,
|
||||||
m_.scale(),
|
m_.scale(),
|
||||||
|
@ -127,18 +126,18 @@ void feature_style_processor<Processor>::apply(double scale_denom)
|
||||||
names);
|
names);
|
||||||
|
|
||||||
// Store active material
|
// Store active material
|
||||||
if (!mat->active_styles_.empty())
|
if (!mat.active_styles_.empty())
|
||||||
{
|
{
|
||||||
mat_list.push_back(mat);
|
mat_list.emplace_back(std::move(mat));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( layer_rendering_material_ptr mat : mat_list )
|
for ( layer_rendering_material const & mat : mat_list )
|
||||||
{
|
{
|
||||||
if (!mat->active_styles_.empty())
|
if (!mat.active_styles_.empty())
|
||||||
{
|
{
|
||||||
render_material(*mat,p);
|
render_material(mat, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,11 +442,11 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
||||||
|
|
||||||
|
|
||||||
template <typename Processor>
|
template <typename Processor>
|
||||||
void feature_style_processor<Processor>::render_material(layer_rendering_material & mat,
|
void feature_style_processor<Processor>::render_material(layer_rendering_material const & mat,
|
||||||
Processor & p )
|
Processor & p )
|
||||||
{
|
{
|
||||||
std::vector<feature_type_style const*> & active_styles = mat.active_styles_;
|
std::vector<feature_type_style const*> const & active_styles = mat.active_styles_;
|
||||||
std::vector<featureset_ptr> & featureset_ptr_list = mat.featureset_ptr_list_;
|
std::vector<featureset_ptr> const & featureset_ptr_list = mat.featureset_ptr_list_;
|
||||||
if (featureset_ptr_list.empty())
|
if (featureset_ptr_list.empty())
|
||||||
{
|
{
|
||||||
// The datasource wasn't queried because of early return
|
// The datasource wasn't queried because of early return
|
||||||
|
@ -464,7 +463,7 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
|
||||||
|
|
||||||
layer const& lay = mat.lay_;
|
layer const& lay = mat.lay_;
|
||||||
|
|
||||||
std::vector<rule_cache> & rule_caches = mat.rule_caches_;
|
std::vector<rule_cache> const & rule_caches = mat.rule_caches_;
|
||||||
|
|
||||||
proj_transform prj_trans(mat.proj0_,mat.proj1_);
|
proj_transform prj_trans(mat.proj0_,mat.proj1_);
|
||||||
|
|
||||||
|
@ -544,7 +543,7 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
std::vector<featureset_ptr>::iterator featuresets = featureset_ptr_list.begin();
|
std::vector<featureset_ptr>::const_iterator featuresets = featureset_ptr_list.cbegin();
|
||||||
for (feature_type_style const* style : active_styles)
|
for (feature_type_style const* style : active_styles)
|
||||||
{
|
{
|
||||||
featureset_ptr features = *featuresets++;
|
featureset_ptr features = *featuresets++;
|
||||||
|
|
|
@ -291,6 +291,7 @@ void csv_datasource::parse_csv(T & stream, std::string const& separator)
|
||||||
if (has_disk_index_) return;
|
if (has_disk_index_) return;
|
||||||
|
|
||||||
std::vector<item_type> boxes;
|
std::vector<item_type> boxes;
|
||||||
|
|
||||||
while (is_first_row || csv_utils::getline_csv(stream, csv_line, newline, quote_))
|
while (is_first_row || csv_utils::getline_csv(stream, csv_line, newline, quote_))
|
||||||
{
|
{
|
||||||
if ((row_limit_ > 0) && (line_number++ > row_limit_))
|
if ((row_limit_ > 0) && (line_number++ > row_limit_))
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5e7fbab23fcd1874d73b9c7a1558f6b0aacc2cf3
|
Subproject commit 76651203a0918a7f85214d0ed561f15741d5e23f
|
|
@ -1 +1 @@
|
||||||
Subproject commit 772ce6023ddadbb4ff0d05b43418899980d390cc
|
Subproject commit 023ffcc01e141eb43f47cee02189b76990792981
|
Loading…
Add table
Reference in a new issue