From 65035706fb75845956882f3c8503042e7f3263b8 Mon Sep 17 00:00:00 2001 From: Mathis Logemann Date: Wed, 26 Jan 2022 23:32:21 +0100 Subject: [PATCH] format dir benchmark --- benchmark/include/bench_framework.hpp | 159 +++---- benchmark/include/compare_images.hpp | 41 +- benchmark/src/normalize_angle.cpp | 90 ++-- benchmark/src/test_array_allocation.cpp | 404 +++++++++--------- benchmark/src/test_expression_parse.cpp | 24 +- benchmark/src/test_face_ptr_creation.cpp | 30 +- benchmark/src/test_font_registration.cpp | 14 +- benchmark/src/test_getline.cpp | 70 ++- benchmark/src/test_marker_cache.cpp | 44 +- benchmark/src/test_noop_rendering.cpp | 28 +- .../src/test_numeric_cast_vs_static_cast.cpp | 58 ++- benchmark/src/test_offset_converter.cpp | 57 +-- benchmark/src/test_png_encoding1.cpp | 20 +- benchmark/src/test_png_encoding2.cpp | 23 +- benchmark/src/test_polygon_clipping.cpp | 159 +++---- .../src/test_polygon_clipping_rendering.cpp | 52 ++- benchmark/src/test_proj_transform1.cpp | 66 +-- benchmark/src/test_quad_tree.cpp | 24 +- benchmark/src/test_rendering.cpp | 72 ++-- benchmark/src/test_rendering_shared_map.cpp | 84 ++-- benchmark/src/test_to_bool.cpp | 24 +- benchmark/src/test_to_double.cpp | 29 +- benchmark/src/test_to_int.cpp | 29 +- benchmark/src/test_to_string1.cpp | 17 +- benchmark/src/test_to_string2.cpp | 13 +- benchmark/src/test_utf_encoding.cpp | 82 ++-- benchmark/template.cpp | 16 +- 27 files changed, 879 insertions(+), 850 deletions(-) diff --git a/benchmark/include/bench_framework.hpp b/benchmark/include/bench_framework.hpp index c7729dd16..593931103 100644 --- a/benchmark/include/bench_framework.hpp +++ b/benchmark/include/bench_framework.hpp @@ -10,7 +10,7 @@ // stl #include -#include // log10, round +#include // log10, round #include // snprintf #include #include @@ -22,36 +22,28 @@ namespace benchmark { -template +template using milliseconds = std::chrono::duration; -template +template using seconds = std::chrono::duration; class test_case { -protected: + protected: mapnik::parameters params_; std::size_t threads_; std::size_t iterations_; -public: + + public: test_case(mapnik::parameters const& params) - : params_(params), - threads_(mapnik::safe_cast(*params.get("threads", 0))), - iterations_(mapnik::safe_cast(*params.get("iterations", 0))) - {} - std::size_t threads() const - { - return threads_; - } - std::size_t iterations() const - { - return iterations_; - } - mapnik::parameters const& params() const - { - return params_; - } + : params_(params) + , threads_(mapnik::safe_cast(*params.get("threads", 0))) + , iterations_(mapnik::safe_cast(*params.get("iterations", 0))) + {} + std::size_t threads() const { return threads_; } + std::size_t iterations() const { return iterations_; } + mapnik::parameters const& params() const { return params_; } virtual bool validate() const = 0; virtual bool operator()() const = 0; }; @@ -59,21 +51,25 @@ public: // gathers --long-option values in 'params'; // returns the index of the first non-option argument, // or negated index of an ill-formed option argument -inline int parse_args(int argc, char** argv, mapnik::parameters & params) +inline int parse_args(int argc, char** argv, mapnik::parameters& params) { - for (int i = 1; i < argc; ++i) { + for (int i = 1; i < argc; ++i) + { const char* opt = argv[i]; - if (opt[0] != '-') { + if (opt[0] != '-') + { // non-option argument, return its index return i; } - if (opt[1] != '-') { + if (opt[1] != '-') + { // we only accept --long-options, but instead of throwing, // just issue a warning and let the caller decide what to do std::clog << argv[0] << ": invalid option '" << opt << "'\n"; return -i; // negative means ill-formed option #i } - if (opt[2] == '\0') { + if (opt[2] == '\0') + { // option-list terminator '--' return i + 1; } @@ -81,15 +77,18 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params) // take option name without the leading '--' std::string key(opt + 2); size_t eq = key.find('='); - if (eq != std::string::npos) { + if (eq != std::string::npos) + { // one-argument form '--foo=bar' params[key.substr(0, eq)] = key.substr(eq + 1); } - else if (i + 1 < argc) { + else if (i + 1 < argc) + { // two-argument form '--foo' 'bar' params[key] = std::string(argv[++i]); } - else { + else + { // missing second argument std::clog << argv[0] << ": missing option '" << opt << "' value\n"; return -i; // negative means ill-formed option #i @@ -100,7 +99,8 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params) inline void handle_common_args(mapnik::parameters const& params) { - if (auto severity = params.get("log")) { + if (auto severity = params.get("log")) + { if (*severity == "debug") mapnik::logger::set_severity(mapnik::logger::debug); else if (*severity == "warn") @@ -110,37 +110,35 @@ inline void handle_common_args(mapnik::parameters const& params) else if (*severity == "none") mapnik::logger::set_severity(mapnik::logger::none); else - std::clog << "ignoring option --log='" << *severity - << "' (allowed values are: debug, warn, error, none)\n"; + std::clog << "ignoring option --log='" << *severity << "' (allowed values are: debug, warn, error, none)\n"; } } -inline int handle_args(int argc, char** argv, mapnik::parameters & params) +inline int handle_args(int argc, char** argv, mapnik::parameters& params) { int res = parse_args(argc, argv, params); handle_common_args(params); return res; } -#define BENCHMARK(test_class,name) \ - int main(int argc, char** argv) \ - { \ - try \ - { \ - mapnik::parameters params; \ - benchmark::handle_args(argc,argv,params); \ - test_class test_runner(params); \ - auto result = run(test_runner,name); \ - testing::run_cleanup(); \ - return result; \ - } \ - catch (std::exception const& ex) \ - { \ - std::clog << ex.what() << "\n"; \ - testing::run_cleanup(); \ - return -1; \ - } \ - } \ +#define BENCHMARK(test_class, name) \ + int main(int argc, char** argv) \ + { \ + try \ + { \ + mapnik::parameters params; \ + benchmark::handle_args(argc, argv, params); \ + test_class test_runner(params); \ + auto result = run(test_runner, name); \ + testing::run_cleanup(); \ + return result; \ + } catch (std::exception const& ex) \ + { \ + std::clog << ex.what() << "\n"; \ + testing::run_cleanup(); \ + return -1; \ + } \ + } struct big_number_fmt { @@ -149,7 +147,9 @@ struct big_number_fmt const char* u; big_number_fmt(int width, double value, int base = 1000) - : w(width), v(value), u("") + : w(width) + , v(value) + , u("") { static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0"; u = suffixes; @@ -165,7 +165,7 @@ struct big_number_fmt } }; -template +template int run(T const& test_runner, std::string const& name) { try @@ -196,8 +196,7 @@ int run(T const& test_runner, std::string const& name) std::mutex mtx_ready; std::unique_lock lock_ready(mtx_ready); - auto stub = [&](T const& test_copy) - { + auto stub = [&](T const& test_copy) { // workers will wait on this mutex until the main thread // constructs all of them and starts measuring time std::unique_lock my_lock(mtx_ready); @@ -207,14 +206,14 @@ int run(T const& test_runner, std::string const& name) std::vector tg; tg.reserve(num_threads); - for (auto i = num_threads; i-- > 0; ) + for (auto i = num_threads; i-- > 0;) { tg.emplace_back(stub, test_runner); } start = std::chrono::high_resolution_clock::now(); lock_ready.unlock(); // wait for all workers to finish - for (auto & t : tg) + for (auto& t : tg) { if (t.joinable()) t.join(); @@ -228,7 +227,8 @@ int run(T const& test_runner, std::string const& name) else { start = std::chrono::high_resolution_clock::now(); - do { + do + { test_runner(); elapsed = std::chrono::high_resolution_clock::now() - start; total_iters += num_iters; @@ -243,21 +243,27 @@ int run(T const& test_runner, std::string const& name) std::clog << std::left << std::setw(43) << name; std::clog << std::resetiosflags(std::ios::adjustfield); - if (num_threads > 0) { - std::clog << ' ' << std::setw(3) << num_threads - << " worker" << (num_threads > 1 ? "s" : " "); + if (num_threads > 0) + { + std::clog << ' ' << std::setw(3) << num_threads << " worker" << (num_threads > 1 ? "s" : " "); } - else { + else + { std::clog << " main thread"; } - std::snprintf(msg, sizeof(msg), - " %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n", - itersf.w, itersf.v, itersf.u, dur_total, - ips.w, ips.v, ips.u); + std::snprintf(msg, + sizeof(msg), + " %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n", + itersf.w, + itersf.v, + itersf.u, + dur_total, + ips.w, + ips.v, + ips.u); std::clog << msg; return 0; - } - catch (std::exception const& ex) + } catch (std::exception const& ex) { std::clog << "test runner did not complete: " << ex.what() << "\n"; return 4; @@ -267,18 +273,15 @@ int run(T const& test_runner, std::string const& name) struct sequencer { sequencer(int argc, char** argv) - : exit_code_(0) + : exit_code_(0) { benchmark::handle_args(argc, argv, params_); } - int done() const - { - return exit_code_; - } + int done() const { return exit_code_; } - template - sequencer & run(std::string const& name, Args && ...args) + template + sequencer& run(std::string const& name, Args&&... args) { // Test instance lifetime is confined to this function Test test_runner(params_, std::forward(args)...); @@ -287,11 +290,11 @@ struct sequencer return *this; // allow chaining calls } -protected: + protected: mapnik::parameters params_; int exit_code_; }; -} +} // namespace benchmark #endif // MAPNIK_BENCH_FRAMEWORK_HPP diff --git a/benchmark/include/compare_images.hpp b/benchmark/include/compare_images.hpp index ff90e01a0..21f34732a 100644 --- a/benchmark/include/compare_images.hpp +++ b/benchmark/include/compare_images.hpp @@ -5,32 +5,31 @@ #include #include - namespace benchmark { - bool compare_images(std::string const& src_fn,std::string const& dest_fn) +bool compare_images(std::string const& src_fn, std::string const& dest_fn) +{ + std::unique_ptr reader1(mapnik::get_image_reader(dest_fn, "png")); + if (!reader1.get()) { - std::unique_ptr reader1(mapnik::get_image_reader(dest_fn,"png")); - if (!reader1.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + dest_fn); - } - - std::unique_ptr reader2(mapnik::get_image_reader(src_fn,"png")); - if (!reader2.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + src_fn); - } - - const mapnik::image_any desc_any = reader1->read(0,0,reader1->width(), reader1->height()); - const mapnik::image_any src_any = reader2->read(0,0,reader2->width(), reader2->height()); - - mapnik::image_rgba8 const& dest = mapnik::util::get(desc_any); - mapnik::image_rgba8 const& src = mapnik::util::get(src_any); - - return compare(dest, src, 0, true) == 0; + throw mapnik::image_reader_exception("Failed to load: " + dest_fn); } + std::unique_ptr reader2(mapnik::get_image_reader(src_fn, "png")); + if (!reader2.get()) + { + throw mapnik::image_reader_exception("Failed to load: " + src_fn); + } + + const mapnik::image_any desc_any = reader1->read(0, 0, reader1->width(), reader1->height()); + const mapnik::image_any src_any = reader2->read(0, 0, reader2->width(), reader2->height()); + + mapnik::image_rgba8 const& dest = mapnik::util::get(desc_any); + mapnik::image_rgba8 const& src = mapnik::util::get(src_any); + + return compare(dest, src, 0, true) == 0; } +} // namespace benchmark + #endif // MAPNIK_COMPARE_IMAGES_HPP diff --git a/benchmark/src/normalize_angle.cpp b/benchmark/src/normalize_angle.cpp index bc137a95f..fcfc7a5c2 100644 --- a/benchmark/src/normalize_angle.cpp +++ b/benchmark/src/normalize_angle.cpp @@ -2,20 +2,23 @@ #include -template +template struct bench_func : benchmark::test_case { - T (* const func_)(T); + T (*const func_)(T); T const value_; bench_func(mapnik::parameters const& params, T (*func)(T), T value) - : test_case(params), func_(func), value_(value) {} + : test_case(params) + , func_(func) + , value_(value) + {} bool validate() const { return true; } - bool operator() () const + bool operator()() const { - for (auto i = this->iterations_; i-- > 0; ) + for (auto i = this->iterations_; i-- > 0;) { func_(value_); } @@ -23,47 +26,46 @@ struct bench_func : benchmark::test_case } }; -#define BENCH_FUNC1(func, value) \ - run>(#func "(" #value ")", func, value) +#define BENCH_FUNC1(func, value) run>(#func "(" #value ")", func, value) int main(int argc, char** argv) { return benchmark::sequencer(argc, argv) - .BENCH_FUNC1(mapnik::util::normalize_angle, +3) - .BENCH_FUNC1(mapnik::util::normalize_angle, +6) - .BENCH_FUNC1(mapnik::util::normalize_angle, +9) - .BENCH_FUNC1(mapnik::util::normalize_angle, +12) - .BENCH_FUNC1(mapnik::util::normalize_angle, +15) - .BENCH_FUNC1(mapnik::util::normalize_angle, +20) - .BENCH_FUNC1(mapnik::util::normalize_angle, +30) - .BENCH_FUNC1(mapnik::util::normalize_angle, +40) - .BENCH_FUNC1(mapnik::util::normalize_angle, +50) - .BENCH_FUNC1(mapnik::util::normalize_angle, +70) - .BENCH_FUNC1(mapnik::util::normalize_angle, +90) - .BENCH_FUNC1(mapnik::util::normalize_angle, +110) - .BENCH_FUNC1(mapnik::util::normalize_angle, +130) - .BENCH_FUNC1(mapnik::util::normalize_angle, +157) - .BENCH_FUNC1(mapnik::util::normalize_angle, +209) - .BENCH_FUNC1(mapnik::util::normalize_angle, +314) - .BENCH_FUNC1(mapnik::util::normalize_angle, +628) - .BENCH_FUNC1(mapnik::util::normalize_angle, +942) - .BENCH_FUNC1(mapnik::util::normalize_angle, -3) - .BENCH_FUNC1(mapnik::util::normalize_angle, -6) - .BENCH_FUNC1(mapnik::util::normalize_angle, -9) - .BENCH_FUNC1(mapnik::util::normalize_angle, -12) - .BENCH_FUNC1(mapnik::util::normalize_angle, -15) - .BENCH_FUNC1(mapnik::util::normalize_angle, -20) - .BENCH_FUNC1(mapnik::util::normalize_angle, -30) - .BENCH_FUNC1(mapnik::util::normalize_angle, -40) - .BENCH_FUNC1(mapnik::util::normalize_angle, -50) - .BENCH_FUNC1(mapnik::util::normalize_angle, -70) - .BENCH_FUNC1(mapnik::util::normalize_angle, -90) - .BENCH_FUNC1(mapnik::util::normalize_angle, -110) - .BENCH_FUNC1(mapnik::util::normalize_angle, -130) - .BENCH_FUNC1(mapnik::util::normalize_angle, -157) - .BENCH_FUNC1(mapnik::util::normalize_angle, -209) - .BENCH_FUNC1(mapnik::util::normalize_angle, -314) - .BENCH_FUNC1(mapnik::util::normalize_angle, -628) - .BENCH_FUNC1(mapnik::util::normalize_angle, -942) - .done(); + .BENCH_FUNC1(mapnik::util::normalize_angle, +3) + .BENCH_FUNC1(mapnik::util::normalize_angle, +6) + .BENCH_FUNC1(mapnik::util::normalize_angle, +9) + .BENCH_FUNC1(mapnik::util::normalize_angle, +12) + .BENCH_FUNC1(mapnik::util::normalize_angle, +15) + .BENCH_FUNC1(mapnik::util::normalize_angle, +20) + .BENCH_FUNC1(mapnik::util::normalize_angle, +30) + .BENCH_FUNC1(mapnik::util::normalize_angle, +40) + .BENCH_FUNC1(mapnik::util::normalize_angle, +50) + .BENCH_FUNC1(mapnik::util::normalize_angle, +70) + .BENCH_FUNC1(mapnik::util::normalize_angle, +90) + .BENCH_FUNC1(mapnik::util::normalize_angle, +110) + .BENCH_FUNC1(mapnik::util::normalize_angle, +130) + .BENCH_FUNC1(mapnik::util::normalize_angle, +157) + .BENCH_FUNC1(mapnik::util::normalize_angle, +209) + .BENCH_FUNC1(mapnik::util::normalize_angle, +314) + .BENCH_FUNC1(mapnik::util::normalize_angle, +628) + .BENCH_FUNC1(mapnik::util::normalize_angle, +942) + .BENCH_FUNC1(mapnik::util::normalize_angle, -3) + .BENCH_FUNC1(mapnik::util::normalize_angle, -6) + .BENCH_FUNC1(mapnik::util::normalize_angle, -9) + .BENCH_FUNC1(mapnik::util::normalize_angle, -12) + .BENCH_FUNC1(mapnik::util::normalize_angle, -15) + .BENCH_FUNC1(mapnik::util::normalize_angle, -20) + .BENCH_FUNC1(mapnik::util::normalize_angle, -30) + .BENCH_FUNC1(mapnik::util::normalize_angle, -40) + .BENCH_FUNC1(mapnik::util::normalize_angle, -50) + .BENCH_FUNC1(mapnik::util::normalize_angle, -70) + .BENCH_FUNC1(mapnik::util::normalize_angle, -90) + .BENCH_FUNC1(mapnik::util::normalize_angle, -110) + .BENCH_FUNC1(mapnik::util::normalize_angle, -130) + .BENCH_FUNC1(mapnik::util::normalize_angle, -157) + .BENCH_FUNC1(mapnik::util::normalize_angle, -209) + .BENCH_FUNC1(mapnik::util::normalize_angle, -314) + .BENCH_FUNC1(mapnik::util::normalize_angle, -628) + .BENCH_FUNC1(mapnik::util::normalize_angle, -942) + .done(); } diff --git a/benchmark/src/test_array_allocation.cpp b/benchmark/src/test_array_allocation.cpp index 186c1620e..592a93d07 100644 --- a/benchmark/src/test_array_allocation.cpp +++ b/benchmark/src/test_array_allocation.cpp @@ -14,15 +14,19 @@ #define FULL_ZERO_CHECK -inline void ensure_zero(uint8_t * data, uint32_t size) { +inline void ensure_zero(uint8_t* data, uint32_t size) +{ #ifdef FULL_ZERO_CHECK - for (std::size_t i=0;i array_; test1(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i array_; test1b(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i array_; test1c(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i(::operator new(sizeof(uint8_t) * size_)); - std::fill(data,data + size_,0); - ensure_zero(data,size_); - ::operator delete(data); - } - return true; + for (std::size_t i = 0; i < iterations_; ++i) + { + uint8_t* data = static_cast(::operator new(sizeof(uint8_t) * size_)); + std::fill(data, data + size_, 0); + ensure_zero(data, size_); + ::operator delete(data); + } + return true; } }; - class test2 : public benchmark::test_case { -public: + public: uint32_t size_; std::vector array_; test2(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i(::operator new(sizeof(uint8_t)*size_)); - memcpy(data, &array_[0], size_); - ensure_zero(data,size_); - ::operator delete(data),data=0; - } - return true; + for (std::size_t i = 0; i < iterations_; ++i) + { + uint8_t* data = static_cast(::operator new(sizeof(uint8_t) * size_)); + memcpy(data, &array_[0], size_); + ensure_zero(data, size_); + ::operator delete(data), data = 0; + } + return true; } }; class test3 : public benchmark::test_case { -public: + public: uint32_t size_; std::vector array_; test3(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i data(size_); - ensure_zero(&data[0],data.size()); - } - return true; + for (std::size_t i = 0; i < iterations_; ++i) + { + std::vector data(size_); + ensure_zero(&data[0], data.size()); + } + return true; } }; - class test3b : public benchmark::test_case { -public: + public: uint32_t size_; std::vector array_; test3b(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i data(0); - data.resize(size_,0); - ensure_zero(&data[0],data.size()); - } - return true; + for (std::size_t i = 0; i < iterations_; ++i) + { + std::vector data(0); + data.resize(size_, 0); + ensure_zero(&data[0], data.size()); + } + return true; } }; - class test3c : public benchmark::test_case { -public: + public: uint32_t size_; std::vector array_; test3c(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i data(0); - data.assign(size_,0); - ensure_zero(&data[0],data.size()); - } - return true; + for (std::size_t i = 0; i < iterations_; ++i) + { + std::vector data(0); + data.assign(size_, 0); + ensure_zero(&data[0], data.size()); + } + return true; } }; class test3d : public benchmark::test_case { -public: + public: uint32_t size_; std::vector array_; test3d(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i data(size_); - for (std::size_t i=0;i data(size_); + for (std::size_t i = 0; i < size_; ++i) + { + if (data[i] != 0) + { + throw std::runtime_error("found non zero value"); + } + } + } + return true; } }; class test4 : public benchmark::test_case { -public: + public: uint32_t size_; std::vector array_; test4(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i array_; test5(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i array_; test5b(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i array_; test6(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i data(static_cast(0),static_cast(size_)); - ensure_zero(&data[0],size_); - } - return true; + for (std::size_t i = 0; i < iterations_; ++i) + { + std::valarray data(static_cast(0), static_cast(size_)); + ensure_zero(&data[0], size_); + } + return true; } }; @@ -335,24 +326,23 @@ public: class test7 : public benchmark::test_case { -public: + public: uint32_t size_; std::vector array_; test7(mapnik::parameters const& params) - : test_case(params), - size_(*params.get("size",256*256)), - array_(size_,0) { } - bool validate() const - { - return true; - } + : test_case(params) + , size_(*params.get("size", 256 * 256)) + , array_(size_, 0) + {} + bool validate() const { return true; } bool operator()() const { - for (std::size_t i=0;i data(size_,0); - ensure_zero(&data[0],size_); - } - return true; + for (std::size_t i = 0; i < iterations_; ++i) + { + boost::container::static_vector data(size_, 0); + ensure_zero(&data[0], size_); + } + return true; } }; #endif @@ -360,20 +350,20 @@ public: int main(int argc, char** argv) { return benchmark::sequencer(argc, argv) - .run("calloc") - .run("malloc/memcpy") - .run("malloc/memset") - .run("operator new/std::fill") - .run("operator new/memcpy") - .run("vector(N)") - .run("vector/resize") - .run("vector/assign") - .run("deque(N)") - .run("std::string range") - .run("std::string &[0]") - .run("valarray") + .run("calloc") + .run("malloc/memcpy") + .run("malloc/memset") + .run("operator new/std::fill") + .run("operator new/memcpy") + .run("vector(N)") + .run("vector/resize") + .run("vector/assign") + .run("deque(N)") + .run("std::string range") + .run("std::string &[0]") + .run("valarray") #if BOOST_VERSION >= 105400 - .run("static_vector") + .run("static_vector") #endif - .done(); + .done(); } diff --git a/benchmark/src/test_expression_parse.cpp b/benchmark/src/test_expression_parse.cpp index f39fb8e84..d35a57ab2 100644 --- a/benchmark/src/test_expression_parse.cpp +++ b/benchmark/src/test_expression_parse.cpp @@ -7,10 +7,12 @@ class test : public benchmark::test_case { std::string expr_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {} + : test_case(params) + , expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") + {} bool validate() const { mapnik::expression_ptr expr = mapnik::parse_expression(expr_); @@ -18,24 +20,24 @@ public: bool ret = (result == expr_); if (!ret) { - std::clog << result << " != " << expr_ << "\n"; + std::clog << result << " != " << expr_ << "\n"; } return ret; } bool operator()() const { - for (std::size_t i=0;i line_data = params.get("line"); - if (line_data) - { - line_data_ = *line_data; - } - } + : test_case(params) + , line_data_("this is one line\nand this is a second line\nand a third line") + { + boost::optional line_data = params.get("line"); + if (line_data) + { + line_data_ = *line_data; + } + } bool validate() const { @@ -25,14 +23,15 @@ public: std::string csv_line; std::stringstream s; s << line_data_; - std::getline(s,csv_line,newline); + std::getline(s, csv_line, 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"; + 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; } @@ -42,29 +41,28 @@ public: std::string csv_line; std::stringstream s; s << line_data_; - for (unsigned i=0;i line_data = params.get("line"); - if (line_data) - { - line_data_ = *line_data; - } - } + : test_case(params) + , line_data_("this is one line\nand this is a second line\nand a third line") + { + boost::optional line_data = params.get("line"); + if (line_data) + { + line_data_ = *line_data; + } + } bool validate() const { @@ -74,14 +72,15 @@ public: std::string csv_line; std::stringstream s; s << line_data_; - csv_utils::getline_csv(s,csv_line,newline,quote); + csv_utils::getline_csv(s, csv_line, newline, quote); 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"; + 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; } @@ -92,9 +91,9 @@ public: std::string csv_line; std::stringstream s; s << line_data_; - for (unsigned i=0;i images_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - images_{ - "./test/data/images/dummy.jpg", - "./test/data/images/dummy.jpeg", - "./test/data/images/dummy.png", - "./test/data/images/dummy.tif", - "./test/data/images/dummy.tiff", - //"./test/data/images/landusepattern.jpeg", // will fail since it is a png - //"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png - "./test/data/svg/octocat.svg", - "./test/data/svg/place-of-worship-24.svg", - "./test/data/svg/point_sm.svg", - "./test/data/svg/point.svg", - "./test/data/svg/airfield-12.svg" - } {} - bool validate() const - { - return true; - } + : test_case(params) + , images_{"./test/data/images/dummy.jpg", + "./test/data/images/dummy.jpeg", + "./test/data/images/dummy.png", + "./test/data/images/dummy.tif", + "./test/data/images/dummy.tiff", + //"./test/data/images/landusepattern.jpeg", // will fail since it is a png + //"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png + "./test/data/svg/octocat.svg", + "./test/data/svg/place-of-worship-24.svg", + "./test/data/svg/point_sm.svg", + "./test/data/svg/point.svg", + "./test/data/svg/airfield-12.svg"} + {} + bool validate() const { return true; } bool operator()() const { unsigned count = 0; - for (std::size_t i=0;i(params); // add whitespace to trigger phony "reprojection" - mapnik::layer lay("layer",m.srs() + " "); + mapnik::layer lay("layer", m.srs() + " "); lay.set_datasource(ds); lay.add_style("style"); m.add_layer(lay); // dummy style to ensure that layer is processed - m.insert_style("style",mapnik::feature_type_style()); + m.insert_style("style", mapnik::feature_type_style()); // dummy bbox, but "valid" because minx and miny are less // with an invalid bbox then layer.visible() returns false // and the initial rendering setup is not run - m.zoom_to_box(mapnik::box2d(-1,-1,0,0)); - for (unsigned i=0;i(-1, -1, 0, 0)); + for (unsigned i = 0; i < iterations_; ++i) { - mapnik::image_rgba8 im(256,256); - mapnik::agg_renderer ren(m,im); + mapnik::image_rgba8 im(256, 256); + mapnik::agg_renderer ren(m, im); ren.apply(); } return true; } }; -BENCHMARK(test,"rendering with reprojection") +BENCHMARK(test, "rendering with reprojection") diff --git a/benchmark/src/test_numeric_cast_vs_static_cast.cpp b/benchmark/src/test_numeric_cast_vs_static_cast.cpp index 9e14bf31e..542006910 100644 --- a/benchmark/src/test_numeric_cast_vs_static_cast.cpp +++ b/benchmark/src/test_numeric_cast_vs_static_cast.cpp @@ -9,23 +9,25 @@ class test_static : public benchmark::test_case { double step_; std::uint8_t start_; -public: + + public: test_static(mapnik::parameters const& params) - : test_case(params), - step_(STEP_NUM), - start_(START_NUM) {} - bool validate() const - { - return true; - } + : test_case(params) + , step_(STEP_NUM) + , start_(START_NUM) + {} + bool validate() const { return true; } bool operator()() const { double value_ = 0.0; std::uint8_t x; - for (std::size_t i=0;i(start_) * value_; - if (c >= 256.0) c = 255.0; - if (c < 0.0) c = 0.0; + if (c >= 256.0) + c = 255.0; + if (c < 0.0) + c = 0.0; x = static_cast(c); value_ += step_; } @@ -33,35 +35,34 @@ public: } }; -using boost::numeric::positive_overflow; using boost::numeric::negative_overflow; +using boost::numeric::positive_overflow; class test_numeric : public benchmark::test_case { double step_; std::uint8_t start_; -public: + + public: test_numeric(mapnik::parameters const& params) - : test_case(params), - step_(STEP_NUM), - start_(START_NUM) {} - bool validate() const - { - return true; - } + : test_case(params) + , step_(STEP_NUM) + , start_(START_NUM) + {} + bool validate() const { return true; } bool operator()() const { double value_ = 0.0; std::uint8_t x; - for (std::size_t i=0;i(start_ * value_); - } - catch(negative_overflow&) + } catch (negative_overflow&) { x = std::numeric_limits::min(); - } - catch(positive_overflow&) + } catch (positive_overflow&) { x = std::numeric_limits::max(); } @@ -73,8 +74,5 @@ public: int main(int argc, char** argv) { - return benchmark::sequencer(argc, argv) - .run("static_cast") - .run("numeric_cast") - .done(); + return benchmark::sequencer(argc, argv).run("static_cast").run("numeric_cast").done(); } diff --git a/benchmark/src/test_offset_converter.cpp b/benchmark/src/test_offset_converter.cpp index c0d25da89..93988ce4c 100644 --- a/benchmark/src/test_offset_converter.cpp +++ b/benchmark/src/test_offset_converter.cpp @@ -14,31 +14,36 @@ struct fake_path cont_type::iterator itr_; fake_path(std::initializer_list l) - : fake_path(l.begin(), l.size()) { - } + : fake_path(l.begin(), l.size()) + {} - fake_path(std::vector const &v) - : fake_path(v.begin(), v.size()) { - } + fake_path(std::vector const& v) + : fake_path(v.begin(), v.size()) + {} - template - fake_path(Itr itr, size_t sz) { + template + fake_path(Itr itr, size_t sz) + { size_t num_coords = sz >> 1; vertices_.reserve(num_coords); - for (size_t i = 0; i < num_coords; ++i) { + for (size_t i = 0; i < num_coords; ++i) + { double x = *itr++; double y = *itr++; unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO; vertices_.push_back(std::make_tuple(x, y, cmd)); - if (i == num_coords - 1) cmd = mapnik::SEG_END; + if (i == num_coords - 1) + cmd = mapnik::SEG_END; vertices_.push_back(std::make_tuple(x, y, cmd)); } itr_ = vertices_.begin(); } - unsigned vertex(double *x, double *y) { - if (itr_ == vertices_.end()) { + unsigned vertex(double* x, double* y) + { + if (itr_ == vertices_.end()) + { return mapnik::SEG_END; } *x = std::get<0>(*itr_); @@ -48,33 +53,30 @@ struct fake_path return cmd; } - void rewind(unsigned) { - itr_ = vertices_.begin(); - } + void rewind(unsigned) { itr_ = vertices_.begin(); } }; class test_offset : public benchmark::test_case { -public: + public: test_offset(mapnik::parameters const& params) - : test_case(params) {} - bool validate() const - { - return true; - } + : test_case(params) + {} + bool validate() const { return true; } bool operator()() const { std::vector path; int mysize = 2500; int x1 = 0; - path.reserve(mysize*2); - for( int i = 0; i < mysize; i++ ) + path.reserve(mysize * 2); + for (int i = 0; i < mysize; i++) { - path.push_back( i ); - path.push_back( 0 ); + path.push_back(i); + path.push_back(0); } fake_path fpath(path); - for (std::size_t i=0;i off_path(fpath); off_path.set_offset(10); unsigned cmd; @@ -88,15 +90,14 @@ public: } }; - int main(int argc, char** argv) { mapnik::parameters params; - benchmark::handle_args(argc,argv,params); + benchmark::handle_args(argc, argv, params); int return_value = 0; { test_offset test_runner(params); - return_value = run(test_runner,"offset_test"); + return_value = run(test_runner, "offset_test"); } return return_value; } diff --git a/benchmark/src/test_png_encoding1.cpp b/benchmark/src/test_png_encoding1.cpp index ec98f2884..9c4cc6f64 100644 --- a/benchmark/src/test_png_encoding1.cpp +++ b/benchmark/src/test_png_encoding1.cpp @@ -4,23 +4,23 @@ class test : public benchmark::test_case { mapnik::image_rgba8 im_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - im_(256,256) {} - bool validate() const - { - return true; - } + : test_case(params) + , im_(256, 256) + {} + bool validate() const { return true; } bool operator()() const { std::string out; - for (std::size_t i=0;i im_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params) { + : test_case(params) + { std::string filename("./benchmark/data/multicolor.png"); - std::unique_ptr reader(mapnik::get_image_reader(filename,"png")); + std::unique_ptr reader(mapnik::get_image_reader(filename, "png")); if (!reader.get()) { throw mapnik::image_reader_exception("Failed to load: " + filename); } - im_ = std::make_shared(reader->width(),reader->height()); - reader->read(0,0,*im_); + im_ = std::make_shared(reader->width(), reader->height()); + reader->read(0, 0, *im_); } bool validate() const { std::string expected("./benchmark/data/multicolor-hextree-expected.png"); std::string actual("./benchmark/data/multicolor-hextree-actual.png"); - mapnik::save_to_file(*im_,actual, "png8:m=h:z=1"); - return benchmark::compare_images(actual,expected); + mapnik::save_to_file(*im_, actual, "png8:m=h:z=1"); + return benchmark::compare_images(actual, expected); } bool operator()() const { std::string out; - for (std::size_t i=0;i const& geom, mapnik::box2d const& extent, std::string const& name) { - using path_type = mapnik::transform_path_adapter>; + using path_type = + mapnik::transform_path_adapter>; using ren_base = agg::renderer_base; using renderer = agg::renderer_scanline_aa_solid; - mapnik::image_rgba8 im(256,256); + mapnik::image_rgba8 im(256, 256); mapnik::fill(im, mapnik::color("white")); - mapnik::box2d padded_extent(155,134,665,466);//extent; + mapnik::box2d padded_extent(155, 134, 665, 466); // extent; padded_extent.pad(10); - mapnik::view_transform tr(im.width(),im.height(),padded_extent,0,0); - agg::rendering_buffer buf(im.bytes(),im.width(),im.height(), im.row_size()); + mapnik::view_transform tr(im.width(), im.height(), padded_extent, 0, 0); + agg::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size()); agg::pixfmt_rgba32_plain pixf(buf); ren_base renb(pixf); renderer ren(renb); - mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"),mapnik::projection("epsg:4326")); - ren.color(agg::rgba8(127,127,127,255)); + mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"), mapnik::projection("epsg:4326")); + ren.color(agg::rgba8(127, 127, 127, 255)); agg::rasterizer_scanline_aa<> ras; for (auto const& poly : geom) { mapnik::geometry::polygon_vertex_adapter va(poly); - path_type path(tr,va,prj_trans); + path_type path(tr, va, prj_trans); ras.add_path(path); } agg::scanline_u8 sl; agg::render_scanlines(ras, sl, ren); - mapnik::save_to_file(im,name); + mapnik::save_to_file(im, name); } class test1 : public benchmark::test_case @@ -70,15 +71,15 @@ class test1 : public benchmark::test_case std::string wkt_in_; mapnik::box2d extent_; std::string expected_; -public: + + public: using conv_clip = agg::conv_clip_polygon>; - test1(mapnik::parameters const& params, - std::string const& wkt_in, - mapnik::box2d const& extent) - : test_case(params), - wkt_in_(wkt_in), - extent_(extent), - expected_("./benchmark/data/polygon_clipping_agg") {} + test1(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d const& extent) + : test_case(params) + , wkt_in_(wkt_in) + , extent_(extent) + , expected_("./benchmark/data/polygon_clipping_agg") + {} bool validate() const { mapnik::geometry::geometry geom; @@ -99,14 +100,8 @@ public: mapnik::geometry::polygon const& poly = mapnik::util::get>(geom); mapnik::geometry::polygon_vertex_adapter va(poly); - conv_clip clipped(va); - clipped.clip_box( - extent_.minx(), - extent_.miny(), - extent_.maxx(), - extent_.maxy()); - + clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy()); clipped.rewind(0); mapnik::geometry::polygon poly2; @@ -118,7 +113,8 @@ public: { if (cmd == mapnik::SEG_MOVETO) { - x0 = x; y0 = y; + x0 = x; + y0 = y; } if (cmd == mapnik::SEG_CLOSE) @@ -126,7 +122,7 @@ public: ring.emplace_back(x0, y0); break; } - ring.emplace_back(x,y); + ring.emplace_back(x, y); } poly2.push_back(std::move(ring)); // interior rings @@ -135,30 +131,31 @@ public: { if (cmd == mapnik::SEG_MOVETO) { - x0 = x; y0 = y; + x0 = x; + y0 = y; } else if (cmd == mapnik::SEG_CLOSE) { - ring.emplace_back(x0,y0); + ring.emplace_back(x0, y0); poly2.push_back(std::move(ring)); ring.clear(); continue; } - ring.emplace_back(x,y); + ring.emplace_back(x, y); } - std::string expect = expected_+".png"; - std::string actual = expected_+"_actual.png"; + std::string expect = expected_ + ".png"; + std::string actual = expected_ + "_actual.png"; mapnik::geometry::multi_polygon mp; mp.emplace_back(poly2); auto env = mapnik::geometry::envelope(mp); if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) { std::clog << "generating expected image: " << expect << "\n"; - render(mp,env,expect); + render(mp, env, expect); } - render(mp,env,actual); - return benchmark::compare_images(actual,expect); + render(mp, env, actual); + return benchmark::compare_images(actual, expect); } bool operator()() const { @@ -178,29 +175,28 @@ public: return false; } bool valid = true; - for (unsigned i=0;i const& poly = mapnik::util::get>(geom); mapnik::geometry::polygon_vertex_adapter va(poly); conv_clip clipped(va); - clipped.clip_box( - extent_.minx(), - extent_.miny(), - extent_.maxx(), - extent_.maxy()); + clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy()); unsigned cmd; - double x,y; + double x, y; // NOTE: this rewind is critical otherwise // agg_conv_adapter_vpgen will give garbage // values for the first vertex clipped.rewind(0); - while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) { + while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) + { count++; } unsigned expected_count = 30; - if (count != expected_count) { - std::clog << "test1: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; + if (count != expected_count) + { + std::clog << "test1: clipping failed: processed " << count << " verticies but expected " + << expected_count << "\n"; valid = false; } } @@ -208,20 +204,19 @@ public: } }; - class test3 : public benchmark::test_case { std::string wkt_in_; mapnik::box2d extent_; std::string expected_; -public: - test3(mapnik::parameters const& params, - std::string const& wkt_in, - mapnik::box2d const& extent) - : test_case(params), - wkt_in_(wkt_in), - extent_(extent), - expected_("./benchmark/data/polygon_clipping_boost") {} + + public: + test3(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d const& extent) + : test_case(params) + , wkt_in_(wkt_in) + , extent_(extent) + , expected_("./benchmark/data/polygon_clipping_boost") + {} bool validate() const { mapnik::geometry::geometry geom; @@ -234,12 +229,12 @@ public: std::clog << "empty geom!\n"; return false; } - if (!geom.is >()) + if (!geom.is>()) { std::clog << "not a polygon!\n"; return false; } - mapnik::geometry::polygon & poly = mapnik::util::get >(geom); + mapnik::geometry::polygon& poly = mapnik::util::get>(geom); mapnik::geometry::correct(poly); mapnik::geometry::linear_ring bbox; @@ -249,15 +244,15 @@ public: bbox.emplace_back(extent_.maxx(), extent_.miny()); bbox.emplace_back(extent_.minx(), extent_.miny()); - std::deque > result; + std::deque> result; boost::geometry::intersection(bbox, poly, result); - std::string expect = expected_+".png"; - std::string actual = expected_+"_actual.png"; + std::string expect = expected_ + ".png"; + std::string actual = expected_ + "_actual.png"; mapnik::geometry::multi_polygon mp; - for (auto const& _geom: result) + for (auto const& _geom : result) { - //std::clog << boost::geometry::dsv(geom) << "\n"; + // std::clog << boost::geometry::dsv(geom) << "\n"; mp.emplace_back(_geom); } mapnik::geometry::geometry geom2(mp); @@ -265,10 +260,10 @@ public: if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) { std::clog << "generating expected image: " << expect << "\n"; - render(mp,env,expect); + render(mp, env, expect); } - render(mp,env,actual); - return benchmark::compare_images(actual,expect); + render(mp, env, actual); + return benchmark::compare_images(actual, expect); } bool operator()() const { @@ -282,12 +277,12 @@ public: std::clog << "empty geom!\n"; return false; } - if (!geom.is >()) + if (!geom.is>()) { std::clog << "not a polygon!\n"; return false; } - mapnik::geometry::polygon & poly = mapnik::util::get >(geom); + mapnik::geometry::polygon& poly = mapnik::util::get>(geom); mapnik::geometry::correct(poly); mapnik::geometry::linear_ring bbox; @@ -298,22 +293,25 @@ public: bbox.emplace_back(extent_.minx(), extent_.miny()); bool valid = true; - for (unsigned i=0;i > result; + std::deque> result; boost::geometry::intersection(bbox, poly, result); unsigned count = 0; for (auto const& _geom : result) { mapnik::geometry::polygon_vertex_adapter va(_geom); unsigned cmd; - double x,y; - while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) { + double x, y; + while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) + { ++count; } unsigned expected_count = 29; - if (count != expected_count) { - std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; + if (count != expected_count) + { + std::clog << "test3: clipping failed: processed " << count << " verticies but expected " + << expected_count << "\n"; valid = false; } } @@ -500,8 +498,8 @@ public: } unsigned expected_count = 29; if (count != expected_count) { - std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; - valid = false; + std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << +expected_count << "\n"; valid = false; } } } @@ -513,13 +511,16 @@ public: int main(int argc, char** argv) { mapnik::parameters params; - benchmark::handle_args(argc,argv,params); + benchmark::handle_args(argc, argv, params); // polygon/rect clipping - // IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190)) - // RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) - // OUT (expected) - // POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190)) + // IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, + // 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 + // 287, 249 334, 229 191, 313 190)) RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) OUT (expected) + // POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 + // 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 + // 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 + // 334, 229 191, 313 190)) #if 0 mapnik::box2d clipping_box(181,106,631,470); std::string filename_("./benchmark/data/polygon.wkt"); @@ -544,5 +545,5 @@ int main(int argc, char** argv) } */ #endif - return 0;// return_value; + return 0; // return_value; } diff --git a/benchmark/src/test_polygon_clipping_rendering.cpp b/benchmark/src/test_polygon_clipping_rendering.cpp index 758505d9d..b0daba0c9 100644 --- a/benchmark/src/test_polygon_clipping_rendering.cpp +++ b/benchmark/src/test_polygon_clipping_rendering.cpp @@ -8,53 +8,51 @@ class test : public benchmark::test_case { std::string xml_; mapnik::box2d extent_; -public: - test(mapnik::parameters const& params, - std::string const& xml, - mapnik::box2d const& extent) - : test_case(params), - xml_(xml), - extent_(extent) - {} + + public: + test(mapnik::parameters const& params, std::string const& xml, mapnik::box2d const& extent) + : test_case(params) + , xml_(xml) + , extent_(extent) + {} bool validate() const { - mapnik::Map m(256,256); - mapnik::load_map(m,xml_); + mapnik::Map m(256, 256); + mapnik::load_map(m, xml_); m.zoom_to_box(extent_); - mapnik::image_rgba8 im(m.width(),m.height()); - mapnik::agg_renderer ren(m,im); + mapnik::image_rgba8 im(m.width(), m.height()); + mapnik::agg_renderer ren(m, im); ren.apply(); - //mapnik::save_to_file(im.data(),"test.png"); + // mapnik::save_to_file(im.data(),"test.png"); return true; } bool operator()() const { - mapnik::Map m(256,256); - mapnik::load_map(m,xml_); + mapnik::Map m(256, 256); + mapnik::load_map(m, xml_); m.zoom_to_box(extent_); - for (unsigned i=0;i ren(m,im); + mapnik::image_rgba8 im(m.width(), m.height()); + mapnik::agg_renderer ren(m, im); ren.apply(); } return true; } }; - int main(int argc, char** argv) { mapnik::parameters params; - benchmark::handle_args(argc,argv,params); + benchmark::handle_args(argc, argv, params); mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); - mapnik::box2d z1(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298); + mapnik::box2d z1(-20037508.3428, -8317435.0606, 20037508.3428, 18399242.7298); // bbox for 16/10491/22911.png - mapnik::box2d z16(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214); + mapnik::box2d z16(-13622912.929097254, 6026906.8062295765, -13621689.93664469, 6028129.79868214); return benchmark::sequencer(argc, argv) - .run("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1) - .run("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1) - .run("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16) - .run("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16) - .done(); + .run("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1) + .run("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1) + .run("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16) + .run("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16) + .done(); } diff --git a/benchmark/src/test_proj_transform1.cpp b/benchmark/src/test_proj_transform1.cpp index be85685d8..96e338ceb 100644 --- a/benchmark/src/test_proj_transform1.cpp +++ b/benchmark/src/test_proj_transform1.cpp @@ -10,45 +10,46 @@ class test : public benchmark::test_case mapnik::box2d from_; mapnik::box2d to_; bool defer_proj_init_; -public: + + public: test(mapnik::parameters const& params, std::string const& src, std::string const& dest, mapnik::box2d const& from, mapnik::box2d const& to, bool defer_proj) - : test_case(params), - src_(src), - dest_(dest), - from_(from), - to_(to), - defer_proj_init_(defer_proj) {} + : test_case(params) + , src_(src) + , dest_(dest) + , from_(from) + , to_(to) + , defer_proj_init_(defer_proj) + {} bool validate() const { - mapnik::projection src(src_,defer_proj_init_); - mapnik::projection dest(dest_,defer_proj_init_); - mapnik::proj_transform tr(src,dest); + mapnik::projection src(src_, defer_proj_init_); + mapnik::projection dest(dest_, defer_proj_init_); + mapnik::proj_transform tr(src, dest); mapnik::box2d bbox = from_; - if (!tr.forward(bbox)) return false; - return ((std::fabs(bbox.minx() - to_.minx()) < .5) && - (std::fabs(bbox.maxx() - to_.maxx()) < .5) && - (std::fabs(bbox.miny() - to_.miny()) < .5) && - (std::fabs(bbox.maxy() - to_.maxy()) < .5) - ); + if (!tr.forward(bbox)) + return false; + return ((std::fabs(bbox.minx() - to_.minx()) < .5) && (std::fabs(bbox.maxx() - to_.maxx()) < .5) && + (std::fabs(bbox.miny() - to_.miny()) < .5) && (std::fabs(bbox.maxy() - to_.maxy()) < .5)); } bool operator()() const { - mapnik::projection src(src_,defer_proj_init_); - mapnik::projection dest(dest_,defer_proj_init_); - mapnik::proj_transform tr(src,dest); - for (std::size_t i=0;i box(j,k,j,k); - if (!tr.forward(box)) throw std::runtime_error("could not transform coords"); + mapnik::box2d box(j, k, j, k); + if (!tr.forward(box)) + throw std::runtime_error("could not transform coords"); } } } @@ -59,16 +60,17 @@ public: // echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857 int main(int argc, char** argv) { - mapnik::box2d from(-180,-80,180,80); - mapnik::box2d to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316); + mapnik::box2d from(-180, -80, 180, 80); + mapnik::box2d to(-20037508.3427892476, -15538711.0963092316, 20037508.3427892476, 15538711.0963092316); std::string from_str("epsg:4326"); std::string to_str("epsg:3857"); std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"); - std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"); + std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m " + "+nadgrids=@null +wktext +no_defs +over"); return benchmark::sequencer(argc, argv) - .run("lonlat->merc epsg (internal)", from_str, to_str, from, to, true) - .run("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true) - .run("merc->lonlat epsg (internal)", to_str, from_str, to, from, true) - .run("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true) - .done(); + .run("lonlat->merc epsg (internal)", from_str, to_str, from, to, true) + .run("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true) + .run("merc->lonlat epsg (internal)", to_str, from_str, to, from, true) + .run("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true) + .done(); } diff --git a/benchmark/src/test_quad_tree.cpp b/benchmark/src/test_quad_tree.cpp index e3aabac7c..ea92e32a5 100644 --- a/benchmark/src/test_quad_tree.cpp +++ b/benchmark/src/test_quad_tree.cpp @@ -6,43 +6,41 @@ using quad_tree_type = mapnik::quad_tree; class test : public benchmark::test_case { -public: + public: test(mapnik::parameters const& params) - : test_case(params) {} + : test_case(params) + {} - bool validate() const - { - return true; - } + bool validate() const { return true; } bool operator()() const { std::random_device rd; std::default_random_engine engine(rd()); std::uniform_int_distribution uniform_dist(0, 2048); - quad_tree_type tree(mapnik::box2d(0,0,2048,2048)); - //populate + quad_tree_type tree(mapnik::box2d(0, 0, 2048, 2048)); + // populate for (size_t i = 0; i < iterations_; ++i) { int cx = uniform_dist(engine); int cy = uniform_dist(engine); int sx = 0.2 * uniform_dist(engine); int sy = 0.2 * uniform_dist(engine); - mapnik::box2d box(cx - sx,cy - sy, cx + sx, cy + sy); + mapnik::box2d box(cx - sx, cy - sy, cx + sx, cy + sy); tree.insert(i, box); } // bounding box query - std::size_t count=0; + std::size_t count = 0; for (size_t i = 0; i < iterations_; ++i) { int cx = uniform_dist(engine); int cy = uniform_dist(engine); int sx = 0.4 * uniform_dist(engine); int sy = 0.4 * uniform_dist(engine); - mapnik::box2d box(cx - sx,cy - sy, cx + sx, cy + sy); + mapnik::box2d box(cx - sx, cy - sy, cx + sx, cy + sy); auto itr = tree.query_in_box(box); auto end = tree.query_end(); - for ( ;itr != end; ++itr) + for (; itr != end; ++itr) { ++count; } @@ -51,4 +49,4 @@ public: } }; -BENCHMARK(test,"quad_tree creation") +BENCHMARK(test, "quad_tree creation") diff --git a/benchmark/src/test_rendering.cpp b/benchmark/src/test_rendering.cpp index beea28969..0ba1fdff4 100644 --- a/benchmark/src/test_rendering.cpp +++ b/benchmark/src/test_rendering.cpp @@ -15,16 +15,17 @@ class test : public benchmark::test_case mapnik::value_integer height_; double scale_factor_; std::string preview_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - xml_(), - extent_(), - width_(*params.get("width",256)), - height_(*params.get("height",256)), - scale_factor_(*params.get("scale_factor",1.0)), - preview_(*params.get("preview","")) - { + : test_case(params) + , xml_() + , extent_() + , width_(*params.get("width", 256)) + , height_(*params.get("height", 256)) + , scale_factor_(*params.get("scale_factor", 1.0)) + , preview_(*params.get("preview", "")) + { boost::optional map = params.get("map"); if (!map) { @@ -43,70 +44,75 @@ public: { throw std::runtime_error("please provide a --extent= arg"); }*/ - - } + } bool validate() const { - mapnik::Map m(width_,height_); - mapnik::load_map(m,xml_,true); - if (extent_.valid()) { + mapnik::Map m(width_, height_); + mapnik::load_map(m, xml_, true); + if (extent_.valid()) + { m.zoom_to_box(extent_); - } else { + } + else + { m.zoom_all(); } - mapnik::image_rgba8 im(m.width(),m.height()); - mapnik::agg_renderer ren(m,im,scale_factor_); + mapnik::image_rgba8 im(m.width(), m.height()); + mapnik::agg_renderer ren(m, im, scale_factor_); ren.apply(); - if (!preview_.empty()) { + if (!preview_.empty()) + { std::clog << "preview available at " << preview_ << "\n"; - mapnik::save_to_file(im,preview_); + mapnik::save_to_file(im, preview_); } return true; } bool operator()() const { - if (!preview_.empty()) { + if (!preview_.empty()) + { return false; } - mapnik::Map m(width_,height_); - mapnik::load_map(m,xml_); - if (extent_.valid()) { + mapnik::Map m(width_, height_); + mapnik::load_map(m, xml_); + if (extent_.valid()) + { m.zoom_to_box(extent_); - } else { + } + else + { m.zoom_all(); } - for (unsigned i=0;i ren(m,im,scale_factor_); + mapnik::image_rgba8 im(m.width(), m.height()); + mapnik::agg_renderer ren(m, im, scale_factor_); ren.apply(); } return true; } }; - int main(int argc, char** argv) { int return_value = 0; try { mapnik::parameters params; - benchmark::handle_args(argc,argv,params); + benchmark::handle_args(argc, argv, params); boost::optional name = params.get("name"); if (!name) { std::clog << "please provide a name for this test\n"; return -1; } - mapnik::freetype_engine::register_fonts("./fonts/",true); + mapnik::freetype_engine::register_fonts("./fonts/", true); mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); { test test_runner(params); - return_value = run(test_runner,*name); + return_value = run(test_runner, *name); } - } - catch (std::exception const& ex) + } catch (std::exception const& ex) { std::clog << ex.what() << "\n"; return -1; diff --git a/benchmark/src/test_rendering_shared_map.cpp b/benchmark/src/test_rendering_shared_map.cpp index 75631f78c..3d16f61fd 100644 --- a/benchmark/src/test_rendering_shared_map.cpp +++ b/benchmark/src/test_rendering_shared_map.cpp @@ -12,14 +12,15 @@ #include #include -template void process_layers(Renderer & ren, - mapnik::request const& m_req, - mapnik::projection const& map_proj, - std::vector const& layers, - double scale_denom) +template +void process_layers(Renderer& ren, + mapnik::request const& m_req, + mapnik::projection const& map_proj, + std::vector const& layers, + double scale_denom) { unsigned layers_size = layers.size(); - for (unsigned i=0; i < layers_size; ++i) + for (unsigned i = 0; i < layers_size; ++i) { mapnik::layer const& lyr = layers[i]; if (lyr.visible(scale_denom)) @@ -50,17 +51,18 @@ class test : public benchmark::test_case double scale_factor_; std::string preview_; mutable mapnik::image_rgba8 im_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - xml_(), - extent_(), - width_(*params.get("width",256)), - height_(*params.get("height",256)), - m_(new mapnik::Map(width_,height_)), - scale_factor_(*params.get("scale_factor",2.0)), - preview_(*params.get("preview","")), - im_(m_->width(),m_->height()) + : test_case(params) + , xml_() + , extent_() + , width_(*params.get("width", 256)) + , height_(*params.get("height", 256)) + , m_(new mapnik::Map(width_, height_)) + , scale_factor_(*params.get("scale_factor", 2.0)) + , preview_(*params.get("preview", "")) + , im_(m_->width(), m_->height()) { boost::optional map = params.get("map"); if (!map) @@ -70,7 +72,7 @@ public: xml_ = *map; boost::optional ext = params.get("extent"); - mapnik::load_map(*m_,xml_,true); + mapnik::load_map(*m_, xml_, true); if (ext && !ext->empty()) { if (!extent_.from_string(*ext)) @@ -87,42 +89,44 @@ public: bool validate() const { - mapnik::request m_req(width_,height_,extent_); + mapnik::request m_req(width_, height_, extent_); mapnik::attributes variables; m_req.set_buffer_size(m_->buffer_size()); - mapnik::projection map_proj(m_->srs(),true); - double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic()); + mapnik::projection map_proj(m_->srs(), true); + double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic()); scale_denom *= scale_factor_; - mapnik::agg_renderer ren(*m_,m_req,variables,im_,scale_factor_); + mapnik::agg_renderer ren(*m_, m_req, variables, im_, scale_factor_); ren.start_map_processing(*m_); std::vector const& layers = m_->layers(); - process_layers(ren,m_req,map_proj,layers,scale_denom); + process_layers(ren, m_req, map_proj, layers, scale_denom); ren.end_map_processing(*m_); - if (!preview_.empty()) { + if (!preview_.empty()) + { std::clog << "preview available at " << preview_ << "\n"; - mapnik::save_to_file(im_,preview_); + mapnik::save_to_file(im_, preview_); } return true; } bool operator()() const { - if (!preview_.empty()) { + if (!preview_.empty()) + { return false; } - for (unsigned i=0;iwidth(),m_->height()); + mapnik::request m_req(width_, height_, extent_); + mapnik::image_rgba8 im(m_->width(), m_->height()); mapnik::attributes variables; m_req.set_buffer_size(m_->buffer_size()); - mapnik::projection map_proj(m_->srs(),true); - double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic()); + mapnik::projection map_proj(m_->srs(), true); + double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic()); scale_denom *= scale_factor_; - mapnik::agg_renderer ren(*m_,m_req,variables,im,scale_factor_); + mapnik::agg_renderer ren(*m_, m_req, variables, im, scale_factor_); ren.start_map_processing(*m_); std::vector const& layers = m_->layers(); - process_layers(ren,m_req,map_proj,layers,scale_denom); + process_layers(ren, m_req, map_proj, layers, scale_denom); ren.end_map_processing(*m_); bool diff = false; mapnik::image_rgba8 const& dest = im; @@ -133,37 +137,37 @@ public: const unsigned int* row_to = dest.get_row(y); for (unsigned int x = 0; x < width_; ++x) { - if (row_from[x] != row_to[x]) diff = true; + if (row_from[x] != row_to[x]) + diff = true; } } - if (diff) throw std::runtime_error("images differ"); + if (diff) + throw std::runtime_error("images differ"); } return true; } }; - int main(int argc, char** argv) { int return_value = 0; try { mapnik::parameters params; - benchmark::handle_args(argc,argv,params); + benchmark::handle_args(argc, argv, params); boost::optional name = params.get("name"); if (!name) { std::clog << "please provide a name for this test\n"; return -1; } - mapnik::freetype_engine::register_fonts("./fonts/",true); + mapnik::freetype_engine::register_fonts("./fonts/", true); mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); { test test_runner(params); - return_value = run(test_runner,*name); + return_value = run(test_runner, *name); } - } - catch (std::exception const& ex) + } catch (std::exception const& ex) { std::clog << ex.what() << "\n"; return -1; diff --git a/benchmark/src/test_to_bool.cpp b/benchmark/src/test_to_bool.cpp index 83759baaa..5a24df984 100644 --- a/benchmark/src/test_to_bool.cpp +++ b/benchmark/src/test_to_bool.cpp @@ -4,27 +4,31 @@ class test : public benchmark::test_case { std::string value_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - value_("true") {} + : test_case(params) + , value_("true") + {} bool validate() const { bool result = false; - mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result); - if (!result) return result; - mapnik::util::string2bool(value_,result); + mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result); + if (!result) + return result; + mapnik::util::string2bool(value_, result); return (result == true); } bool operator()() const { - for (std::size_t i=0;ibool") +BENCHMARK(test, "string->bool") diff --git a/benchmark/src/test_to_double.cpp b/benchmark/src/test_to_double.cpp index 9fcd2d52f..b99218df4 100644 --- a/benchmark/src/test_to_double.cpp +++ b/benchmark/src/test_to_double.cpp @@ -4,29 +4,36 @@ class test : public benchmark::test_case { std::string value_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - value_("1.23456789") {} + : test_case(params) + , value_("1.23456789") + {} bool validate() const { double result = 0; - if (!mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result)) return false; - if (result != 1.23456789) return false; + if (!mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result)) + return false; + if (result != 1.23456789) + return false; result = 0; - if (!mapnik::util::string2double(value_,result)) return false; - if (result != 1.23456789) return false; + if (!mapnik::util::string2double(value_, result)) + return false; + if (result != 1.23456789) + return false; return true; } bool operator()() const { - for (std::size_t i=0;idouble") +BENCHMARK(test, "string->double") diff --git a/benchmark/src/test_to_int.cpp b/benchmark/src/test_to_int.cpp index c8367c63e..d705ce979 100644 --- a/benchmark/src/test_to_int.cpp +++ b/benchmark/src/test_to_int.cpp @@ -4,29 +4,36 @@ class test : public benchmark::test_case { std::string value_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - value_("123456789") {} + : test_case(params) + , value_("123456789") + {} bool validate() const { mapnik::value_integer result = 0; - if (!mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result)) return false; - if (result != 123456789) return false; + if (!mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result)) + return false; + if (result != 123456789) + return false; result = 0; - if (!mapnik::util::string2int(value_,result)) return false; - if (result != 123456789) return false; + if (!mapnik::util::string2int(value_, result)) + return false; + if (result != 123456789) + return false; return true; } bool operator()() const { - for (std::size_t i=0;iint") +BENCHMARK(test, "string->int") diff --git a/benchmark/src/test_to_string1.cpp b/benchmark/src/test_to_string1.cpp index 187d231e5..003b36a15 100644 --- a/benchmark/src/test_to_string1.cpp +++ b/benchmark/src/test_to_string1.cpp @@ -4,25 +4,28 @@ class test : public benchmark::test_case { double value_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - value_(-0.1234) {} + : test_case(params) + , value_(-0.1234) + {} bool validate() const { std::string s; - mapnik::util::to_string(s,value_); + mapnik::util::to_string(s, value_); return (s == "-0.1234"); } bool operator()() const { std::string out; - for (std::size_t i=0;istring") +BENCHMARK(test, "to_string double->string") diff --git a/benchmark/src/test_to_string2.cpp b/benchmark/src/test_to_string2.cpp index c1797111d..a39233840 100644 --- a/benchmark/src/test_to_string2.cpp +++ b/benchmark/src/test_to_string2.cpp @@ -4,10 +4,12 @@ class test : public benchmark::test_case { double value_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - value_(-0.1234) {} + : test_case(params) + , value_(-0.1234) + {} bool validate() const { std::ostringstream s; @@ -17,7 +19,8 @@ public: bool operator()() const { std::string out; - for (std::size_t i=0;istring") +BENCHMARK(test, "ostringstream double->string") diff --git a/benchmark/src/test_utf_encoding.cpp b/benchmark/src/test_utf_encoding.cpp index 87224ecbf..badb0a661 100644 --- a/benchmark/src/test_utf_encoding.cpp +++ b/benchmark/src/test_utf_encoding.cpp @@ -13,27 +13,29 @@ using mapnik::util::from_u8string; class test : public benchmark::test_case { std::string utf8_; -public: + + public: test(mapnik::parameters const& params) - : test_case(params), - utf8_(from_u8string(u8"שלום")) {} + : test_case(params) + , utf8_(from_u8string(u8"שלום")) + {} bool validate() const { std::wstring_convert, char32_t> utf32conv; std::u32string utf32 = utf32conv.from_bytes(utf8_); - if (utf32.size() != 4) return false; - if (utf32[0] != 0x5e9 && - utf32[1] != 0x5dc && - utf32[2] != 0x5d5 && - utf32[3] != 0x5dd) return false; + if (utf32.size() != 4) + return false; + if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd) + return false; return true; } bool operator()() const { std::u32string utf32; std::wstring_convert, char32_t> utf32conv; - for (std::size_t i=0;i(utf8_); - if (utf32.size() != 4) return false; - if (utf32[0] != 0x5e9 && - utf32[1] != 0x5dc && - utf32[2] != 0x5d5 && - utf32[3] != 0x5dd) return false; + if (utf32.size() != 4) + return false; + if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd) + return false; return true; } bool operator()() const { - std::u32string utf32; - for (std::size_t i=0;i(utf8_); - } + std::u32string utf32; + for (std::size_t i = 0; i < iterations_; ++i) + { + utf32 = boost::locale::conv::utf_to_utf(utf8_); + } return true; } }; @@ -71,28 +75,30 @@ public: class test3 : public benchmark::test_case { std::string utf8_; -public: + + public: test3(mapnik::parameters const& params) - : test_case(params), - utf8_(from_u8string(u8"שלום")) {} + : test_case(params) + , utf8_(from_u8string(u8"שלום")) + {} bool validate() const { mapnik::transcoder tr_("utf-8"); - mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(),utf8_.size()); - //std::u32string utf32 = boost::locale::conv::utf_to_utf(utf8_); - if (utf32.length() != 4) return false; - if (utf32[0] != 0x5e9 && - utf32[1] != 0x5dc && - utf32[2] != 0x5d5 && - utf32[3] != 0x5dd) return false; + mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(), utf8_.size()); + // std::u32string utf32 = boost::locale::conv::utf_to_utf(utf8_); + if (utf32.length() != 4) + return false; + if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd) + return false; return true; } bool operator()() const { mapnik::transcoder tr_("utf-8"); mapnik::value_unicode_string utf32; - for (std::size_t i=0;i is not supported on __linux__\n"; #endif test2 test_runner2(params); - return_value = return_value | run(test_runner2,"utf encode boost::locale"); + return_value = return_value | run(test_runner2, "utf encode boost::locale"); test3 test_runner3(params); - return_value = return_value | run(test_runner3,"utf encode ICU"); + return_value = return_value | run(test_runner3, "utf encode ICU"); return return_value; } diff --git a/benchmark/template.cpp b/benchmark/template.cpp index a91ecb36a..706649d3f 100644 --- a/benchmark/template.cpp +++ b/benchmark/template.cpp @@ -2,16 +2,12 @@ class test : public benchmark::test_case { -public: + public: test(mapnik::parameters const& params) - : test_case(params) {} - bool validate() const - { - return true; - } - void operator()() const - { - } + : test_case(params) + {} + bool validate() const { return true; } + void operator()() const {} }; -BENCHMARK(test,"test name") +BENCHMARK(test, "test name")