Merge remote-tracking branch 'origin/master'

Conflicts:
	plugins/input/csv/csv_datasource.cpp
This commit is contained in:
artemp 2015-10-02 12:27:28 +01:00
commit 1bccca9ff8
10 changed files with 148 additions and 22 deletions

View file

@ -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:

View file

@ -9,7 +9,7 @@ function run {
${BASE}/$1 --threads 0 --iterations $3;
${BASE}/$1 --threads $2 --iterations $(expr $3 / $2);
}
run test_getline 30 10000000
#run test_array_allocation 20 100000
#run test_png_encoding1 10 1000
#run test_png_encoding2 10 50

125
benchmark/test_getline.cpp Normal file
View 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;
}

View file

@ -28,7 +28,7 @@ public:
boost::optional<std::string> map = params.get<std::string>("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;

View file

@ -110,7 +110,7 @@ private:
/*!
* \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_;
};

View file

@ -69,11 +69,10 @@ struct layer_rendering_material
lay_(lay),
proj0_(dest),
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>
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
: m_(m)
@ -102,7 +101,7 @@ void feature_style_processor<Processor>::apply(double scale_denom)
// in a second time, we fetch the results and
// 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
// implementing asynchronous queries
@ -113,9 +112,9 @@ void feature_style_processor<Processor>::apply(double scale_denom)
if (lyr.visible(scale_denom))
{
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,
p,
m_.scale(),
@ -127,18 +126,18 @@ void feature_style_processor<Processor>::apply(double scale_denom)
names);
// 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>
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 )
{
std::vector<feature_type_style const*> & active_styles = mat.active_styles_;
std::vector<featureset_ptr> & featureset_ptr_list = mat.featureset_ptr_list_;
std::vector<feature_type_style const*> const & active_styles = mat.active_styles_;
std::vector<featureset_ptr> const & featureset_ptr_list = mat.featureset_ptr_list_;
if (featureset_ptr_list.empty())
{
// 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_;
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_);
@ -544,7 +543,7 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
else
{
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)
{
featureset_ptr features = *featuresets++;

View file

@ -291,6 +291,7 @@ void csv_datasource::parse_csv(T & stream, std::string const& separator)
if (has_disk_index_) return;
std::vector<item_type> boxes;
while (is_first_row || csv_utils::getline_csv(stream, csv_line, newline, quote_))
{
if ((row_limit_ > 0) && (line_number++ > row_limit_))

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;
if (locator.type == geometry_column_locator::WKT)

@ -1 +1 @@
Subproject commit 5e7fbab23fcd1874d73b9c7a1558f6b0aacc2cf3
Subproject commit 76651203a0918a7f85214d0ed561f15741d5e23f

@ -1 +1 @@
Subproject commit 772ce6023ddadbb4ff0d05b43418899980d390cc
Subproject commit 023ffcc01e141eb43f47cee02189b76990792981