format dir benchmark

This commit is contained in:
Mathis Logemann 2022-01-26 23:32:21 +01:00
parent 6dcf754077
commit 65035706fb
27 changed files with 879 additions and 850 deletions

View file

@ -10,7 +10,7 @@
// stl // stl
#include <chrono> #include <chrono>
#include <cmath> // log10, round #include <cmath> // log10, round
#include <cstdio> // snprintf #include <cstdio> // snprintf
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
@ -22,36 +22,28 @@
namespace benchmark { namespace benchmark {
template <typename T> template<typename T>
using milliseconds = std::chrono::duration<T, std::milli>; using milliseconds = std::chrono::duration<T, std::milli>;
template <typename T> template<typename T>
using seconds = std::chrono::duration<T>; using seconds = std::chrono::duration<T>;
class test_case class test_case
{ {
protected: protected:
mapnik::parameters params_; mapnik::parameters params_;
std::size_t threads_; std::size_t threads_;
std::size_t iterations_; std::size_t iterations_;
public:
public:
test_case(mapnik::parameters const& params) test_case(mapnik::parameters const& params)
: params_(params), : params_(params)
threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0))), , threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0)))
iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0))) , iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0)))
{} {}
std::size_t threads() const std::size_t threads() const { return threads_; }
{ std::size_t iterations() const { return iterations_; }
return threads_; mapnik::parameters const& params() const { return params_; }
}
std::size_t iterations() const
{
return iterations_;
}
mapnik::parameters const& params() const
{
return params_;
}
virtual bool validate() const = 0; virtual bool validate() const = 0;
virtual bool operator()() const = 0; virtual bool operator()() const = 0;
}; };
@ -59,21 +51,25 @@ public:
// gathers --long-option values in 'params'; // gathers --long-option values in 'params';
// returns the index of the first non-option argument, // returns the index of the first non-option argument,
// or negated index of an ill-formed 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]; const char* opt = argv[i];
if (opt[0] != '-') { if (opt[0] != '-')
{
// non-option argument, return its index // non-option argument, return its index
return i; return i;
} }
if (opt[1] != '-') { if (opt[1] != '-')
{
// we only accept --long-options, but instead of throwing, // we only accept --long-options, but instead of throwing,
// just issue a warning and let the caller decide what to do // just issue a warning and let the caller decide what to do
std::clog << argv[0] << ": invalid option '" << opt << "'\n"; std::clog << argv[0] << ": invalid option '" << opt << "'\n";
return -i; // negative means ill-formed option #i return -i; // negative means ill-formed option #i
} }
if (opt[2] == '\0') { if (opt[2] == '\0')
{
// option-list terminator '--' // option-list terminator '--'
return i + 1; return i + 1;
} }
@ -81,15 +77,18 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params)
// take option name without the leading '--' // take option name without the leading '--'
std::string key(opt + 2); std::string key(opt + 2);
size_t eq = key.find('='); size_t eq = key.find('=');
if (eq != std::string::npos) { if (eq != std::string::npos)
{
// one-argument form '--foo=bar' // one-argument form '--foo=bar'
params[key.substr(0, eq)] = key.substr(eq + 1); params[key.substr(0, eq)] = key.substr(eq + 1);
} }
else if (i + 1 < argc) { else if (i + 1 < argc)
{
// two-argument form '--foo' 'bar' // two-argument form '--foo' 'bar'
params[key] = std::string(argv[++i]); params[key] = std::string(argv[++i]);
} }
else { else
{
// missing second argument // missing second argument
std::clog << argv[0] << ": missing option '" << opt << "' value\n"; std::clog << argv[0] << ": missing option '" << opt << "' value\n";
return -i; // negative means ill-formed option #i 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) inline void handle_common_args(mapnik::parameters const& params)
{ {
if (auto severity = params.get<std::string>("log")) { if (auto severity = params.get<std::string>("log"))
{
if (*severity == "debug") if (*severity == "debug")
mapnik::logger::set_severity(mapnik::logger::debug); mapnik::logger::set_severity(mapnik::logger::debug);
else if (*severity == "warn") else if (*severity == "warn")
@ -110,37 +110,35 @@ inline void handle_common_args(mapnik::parameters const& params)
else if (*severity == "none") else if (*severity == "none")
mapnik::logger::set_severity(mapnik::logger::none); mapnik::logger::set_severity(mapnik::logger::none);
else else
std::clog << "ignoring option --log='" << *severity std::clog << "ignoring option --log='" << *severity << "' (allowed values are: debug, warn, error, none)\n";
<< "' (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); int res = parse_args(argc, argv, params);
handle_common_args(params); handle_common_args(params);
return res; return res;
} }
#define BENCHMARK(test_class,name) \ #define BENCHMARK(test_class, name) \
int main(int argc, char** argv) \ int main(int argc, char** argv) \
{ \ { \
try \ try \
{ \ { \
mapnik::parameters params; \ mapnik::parameters params; \
benchmark::handle_args(argc,argv,params); \ benchmark::handle_args(argc, argv, params); \
test_class test_runner(params); \ test_class test_runner(params); \
auto result = run(test_runner,name); \ auto result = run(test_runner, name); \
testing::run_cleanup(); \ testing::run_cleanup(); \
return result; \ return result; \
} \ } catch (std::exception const& ex) \
catch (std::exception const& ex) \ { \
{ \ std::clog << ex.what() << "\n"; \
std::clog << ex.what() << "\n"; \ testing::run_cleanup(); \
testing::run_cleanup(); \ return -1; \
return -1; \ } \
} \ }
} \
struct big_number_fmt struct big_number_fmt
{ {
@ -149,7 +147,9 @@ struct big_number_fmt
const char* u; const char* u;
big_number_fmt(int width, double value, int base = 1000) 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"; static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0";
u = suffixes; u = suffixes;
@ -165,7 +165,7 @@ struct big_number_fmt
} }
}; };
template <typename T> template<typename T>
int run(T const& test_runner, std::string const& name) int run(T const& test_runner, std::string const& name)
{ {
try try
@ -196,8 +196,7 @@ int run(T const& test_runner, std::string const& name)
std::mutex mtx_ready; std::mutex mtx_ready;
std::unique_lock<std::mutex> lock_ready(mtx_ready); std::unique_lock<std::mutex> 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 // workers will wait on this mutex until the main thread
// constructs all of them and starts measuring time // constructs all of them and starts measuring time
std::unique_lock<std::mutex> my_lock(mtx_ready); std::unique_lock<std::mutex> my_lock(mtx_ready);
@ -207,14 +206,14 @@ int run(T const& test_runner, std::string const& name)
std::vector<std::thread> tg; std::vector<std::thread> tg;
tg.reserve(num_threads); tg.reserve(num_threads);
for (auto i = num_threads; i-- > 0; ) for (auto i = num_threads; i-- > 0;)
{ {
tg.emplace_back(stub, test_runner); tg.emplace_back(stub, test_runner);
} }
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
lock_ready.unlock(); lock_ready.unlock();
// wait for all workers to finish // wait for all workers to finish
for (auto & t : tg) for (auto& t : tg)
{ {
if (t.joinable()) if (t.joinable())
t.join(); t.join();
@ -228,7 +227,8 @@ int run(T const& test_runner, std::string const& name)
else else
{ {
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
do { do
{
test_runner(); test_runner();
elapsed = std::chrono::high_resolution_clock::now() - start; elapsed = std::chrono::high_resolution_clock::now() - start;
total_iters += num_iters; 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::left << std::setw(43) << name;
std::clog << std::resetiosflags(std::ios::adjustfield); std::clog << std::resetiosflags(std::ios::adjustfield);
if (num_threads > 0) { if (num_threads > 0)
std::clog << ' ' << std::setw(3) << num_threads {
<< " worker" << (num_threads > 1 ? "s" : " "); std::clog << ' ' << std::setw(3) << num_threads << " worker" << (num_threads > 1 ? "s" : " ");
} }
else { else
{
std::clog << " main thread"; std::clog << " main thread";
} }
std::snprintf(msg, sizeof(msg), std::snprintf(msg,
" %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n", sizeof(msg),
itersf.w, itersf.v, itersf.u, dur_total, " %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n",
ips.w, ips.v, ips.u); itersf.w,
itersf.v,
itersf.u,
dur_total,
ips.w,
ips.v,
ips.u);
std::clog << msg; std::clog << msg;
return 0; return 0;
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::clog << "test runner did not complete: " << ex.what() << "\n"; std::clog << "test runner did not complete: " << ex.what() << "\n";
return 4; return 4;
@ -267,18 +273,15 @@ int run(T const& test_runner, std::string const& name)
struct sequencer struct sequencer
{ {
sequencer(int argc, char** argv) sequencer(int argc, char** argv)
: exit_code_(0) : exit_code_(0)
{ {
benchmark::handle_args(argc, argv, params_); benchmark::handle_args(argc, argv, params_);
} }
int done() const int done() const { return exit_code_; }
{
return exit_code_;
}
template <typename Test, typename... Args> template<typename Test, typename... Args>
sequencer & run(std::string const& name, Args && ...args) sequencer& run(std::string const& name, Args&&... args)
{ {
// Test instance lifetime is confined to this function // Test instance lifetime is confined to this function
Test test_runner(params_, std::forward<Args>(args)...); Test test_runner(params_, std::forward<Args>(args)...);
@ -287,11 +290,11 @@ struct sequencer
return *this; // allow chaining calls return *this; // allow chaining calls
} }
protected: protected:
mapnik::parameters params_; mapnik::parameters params_;
int exit_code_; int exit_code_;
}; };
} } // namespace benchmark
#endif // MAPNIK_BENCH_FRAMEWORK_HPP #endif // MAPNIK_BENCH_FRAMEWORK_HPP

View file

@ -5,32 +5,31 @@
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/image_reader.hpp> #include <mapnik/image_reader.hpp>
namespace benchmark { 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<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn, "png"));
if (!reader1.get())
{ {
std::unique_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn,"png")); throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
if (!reader1.get())
{
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
}
std::unique_ptr<mapnik::image_reader> 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<mapnik::image_rgba8>(desc_any);
mapnik::image_rgba8 const& src = mapnik::util::get<mapnik::image_rgba8>(src_any);
return compare(dest, src, 0, true) == 0;
} }
std::unique_ptr<mapnik::image_reader> 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<mapnik::image_rgba8>(desc_any);
mapnik::image_rgba8 const& src = mapnik::util::get<mapnik::image_rgba8>(src_any);
return compare(dest, src, 0, true) == 0;
} }
} // namespace benchmark
#endif // MAPNIK_COMPARE_IMAGES_HPP #endif // MAPNIK_COMPARE_IMAGES_HPP

View file

@ -2,20 +2,23 @@
#include <mapnik/util/math.hpp> #include <mapnik/util/math.hpp>
template <typename T> template<typename T>
struct bench_func : benchmark::test_case struct bench_func : benchmark::test_case
{ {
T (* const func_)(T); T (*const func_)(T);
T const value_; T const value_;
bench_func(mapnik::parameters const& params, T (*func)(T), T 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 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_); func_(value_);
} }
@ -23,47 +26,46 @@ struct bench_func : benchmark::test_case
} }
}; };
#define BENCH_FUNC1(func, value) \ #define BENCH_FUNC1(func, value) run<bench_func<double>>(#func "(" #value ")", func, value)
run<bench_func<double>>(#func "(" #value ")", func, value)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.BENCH_FUNC1(mapnik::util::normalize_angle, +3) .BENCH_FUNC1(mapnik::util::normalize_angle, +3)
.BENCH_FUNC1(mapnik::util::normalize_angle, +6) .BENCH_FUNC1(mapnik::util::normalize_angle, +6)
.BENCH_FUNC1(mapnik::util::normalize_angle, +9) .BENCH_FUNC1(mapnik::util::normalize_angle, +9)
.BENCH_FUNC1(mapnik::util::normalize_angle, +12) .BENCH_FUNC1(mapnik::util::normalize_angle, +12)
.BENCH_FUNC1(mapnik::util::normalize_angle, +15) .BENCH_FUNC1(mapnik::util::normalize_angle, +15)
.BENCH_FUNC1(mapnik::util::normalize_angle, +20) .BENCH_FUNC1(mapnik::util::normalize_angle, +20)
.BENCH_FUNC1(mapnik::util::normalize_angle, +30) .BENCH_FUNC1(mapnik::util::normalize_angle, +30)
.BENCH_FUNC1(mapnik::util::normalize_angle, +40) .BENCH_FUNC1(mapnik::util::normalize_angle, +40)
.BENCH_FUNC1(mapnik::util::normalize_angle, +50) .BENCH_FUNC1(mapnik::util::normalize_angle, +50)
.BENCH_FUNC1(mapnik::util::normalize_angle, +70) .BENCH_FUNC1(mapnik::util::normalize_angle, +70)
.BENCH_FUNC1(mapnik::util::normalize_angle, +90) .BENCH_FUNC1(mapnik::util::normalize_angle, +90)
.BENCH_FUNC1(mapnik::util::normalize_angle, +110) .BENCH_FUNC1(mapnik::util::normalize_angle, +110)
.BENCH_FUNC1(mapnik::util::normalize_angle, +130) .BENCH_FUNC1(mapnik::util::normalize_angle, +130)
.BENCH_FUNC1(mapnik::util::normalize_angle, +157) .BENCH_FUNC1(mapnik::util::normalize_angle, +157)
.BENCH_FUNC1(mapnik::util::normalize_angle, +209) .BENCH_FUNC1(mapnik::util::normalize_angle, +209)
.BENCH_FUNC1(mapnik::util::normalize_angle, +314) .BENCH_FUNC1(mapnik::util::normalize_angle, +314)
.BENCH_FUNC1(mapnik::util::normalize_angle, +628) .BENCH_FUNC1(mapnik::util::normalize_angle, +628)
.BENCH_FUNC1(mapnik::util::normalize_angle, +942) .BENCH_FUNC1(mapnik::util::normalize_angle, +942)
.BENCH_FUNC1(mapnik::util::normalize_angle, -3) .BENCH_FUNC1(mapnik::util::normalize_angle, -3)
.BENCH_FUNC1(mapnik::util::normalize_angle, -6) .BENCH_FUNC1(mapnik::util::normalize_angle, -6)
.BENCH_FUNC1(mapnik::util::normalize_angle, -9) .BENCH_FUNC1(mapnik::util::normalize_angle, -9)
.BENCH_FUNC1(mapnik::util::normalize_angle, -12) .BENCH_FUNC1(mapnik::util::normalize_angle, -12)
.BENCH_FUNC1(mapnik::util::normalize_angle, -15) .BENCH_FUNC1(mapnik::util::normalize_angle, -15)
.BENCH_FUNC1(mapnik::util::normalize_angle, -20) .BENCH_FUNC1(mapnik::util::normalize_angle, -20)
.BENCH_FUNC1(mapnik::util::normalize_angle, -30) .BENCH_FUNC1(mapnik::util::normalize_angle, -30)
.BENCH_FUNC1(mapnik::util::normalize_angle, -40) .BENCH_FUNC1(mapnik::util::normalize_angle, -40)
.BENCH_FUNC1(mapnik::util::normalize_angle, -50) .BENCH_FUNC1(mapnik::util::normalize_angle, -50)
.BENCH_FUNC1(mapnik::util::normalize_angle, -70) .BENCH_FUNC1(mapnik::util::normalize_angle, -70)
.BENCH_FUNC1(mapnik::util::normalize_angle, -90) .BENCH_FUNC1(mapnik::util::normalize_angle, -90)
.BENCH_FUNC1(mapnik::util::normalize_angle, -110) .BENCH_FUNC1(mapnik::util::normalize_angle, -110)
.BENCH_FUNC1(mapnik::util::normalize_angle, -130) .BENCH_FUNC1(mapnik::util::normalize_angle, -130)
.BENCH_FUNC1(mapnik::util::normalize_angle, -157) .BENCH_FUNC1(mapnik::util::normalize_angle, -157)
.BENCH_FUNC1(mapnik::util::normalize_angle, -209) .BENCH_FUNC1(mapnik::util::normalize_angle, -209)
.BENCH_FUNC1(mapnik::util::normalize_angle, -314) .BENCH_FUNC1(mapnik::util::normalize_angle, -314)
.BENCH_FUNC1(mapnik::util::normalize_angle, -628) .BENCH_FUNC1(mapnik::util::normalize_angle, -628)
.BENCH_FUNC1(mapnik::util::normalize_angle, -942) .BENCH_FUNC1(mapnik::util::normalize_angle, -942)
.done(); .done();
} }

View file

@ -14,15 +14,19 @@
#define FULL_ZERO_CHECK #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 #ifdef FULL_ZERO_CHECK
for (std::size_t i=0;i<size;++i) { for (std::size_t i = 0; i < size; ++i)
if (data[i] != 0) { {
if (data[i] != 0)
{
throw std::runtime_error("found non zero value"); throw std::runtime_error("found non zero value");
} }
} }
#else #else
if (data[0] != 0) { if (data[0] != 0)
{
throw std::runtime_error("found non zero value"); throw std::runtime_error("found non zero value");
} }
#endif #endif
@ -30,274 +34,262 @@ inline void ensure_zero(uint8_t * data, uint32_t size) {
class test1 : public benchmark::test_case class test1 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1(mapnik::parameters const& params) test1(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
// NOTE: sizeof(uint8_t) == 1 {
uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_); // NOTE: sizeof(uint8_t) == 1
memcpy(data, &array_[0], size_); uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
ensure_zero(data,size_); memcpy(data, &array_[0], size_);
free(data); ensure_zero(data, size_);
} free(data);
return true; }
return true;
} }
}; };
class test1b : public benchmark::test_case class test1b : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1b(mapnik::parameters const& params) test1b(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
// NOTE: sizeof(uint8_t) == 1 {
uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_); // NOTE: sizeof(uint8_t) == 1
memset(data, 0, sizeof(uint8_t)*size_); uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
ensure_zero(data,size_); memset(data, 0, sizeof(uint8_t) * size_);
free(data); ensure_zero(data, size_);
} free(data);
return true; }
return true;
} }
}; };
class test1c : public benchmark::test_case class test1c : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1c(mapnik::parameters const& params) test1c(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
uint8_t *data = static_cast<uint8_t *>(::operator new(sizeof(uint8_t) * size_)); {
std::fill(data,data + size_,0); uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
ensure_zero(data,size_); std::fill(data, data + size_, 0);
::operator delete(data); ensure_zero(data, size_);
} ::operator delete(data);
return true; }
return true;
} }
}; };
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
uint8_t * data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t)*size_)); {
memcpy(data, &array_[0], size_); uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
ensure_zero(data,size_); memcpy(data, &array_[0], size_);
::operator delete(data),data=0; ensure_zero(data, size_);
} ::operator delete(data), data = 0;
return true; }
return true;
} }
}; };
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3(mapnik::parameters const& params) test3(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
std::vector<uint8_t> data(size_); {
ensure_zero(&data[0],data.size()); std::vector<uint8_t> data(size_);
} ensure_zero(&data[0], data.size());
return true; }
return true;
} }
}; };
class test3b : public benchmark::test_case class test3b : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3b(mapnik::parameters const& params) test3b(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
std::vector<uint8_t> data(0); {
data.resize(size_,0); std::vector<uint8_t> data(0);
ensure_zero(&data[0],data.size()); data.resize(size_, 0);
} ensure_zero(&data[0], data.size());
return true; }
return true;
} }
}; };
class test3c : public benchmark::test_case class test3c : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3c(mapnik::parameters const& params) test3c(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
std::vector<uint8_t> data(0); {
data.assign(size_,0); std::vector<uint8_t> data(0);
ensure_zero(&data[0],data.size()); data.assign(size_, 0);
} ensure_zero(&data[0], data.size());
return true; }
return true;
} }
}; };
class test3d : public benchmark::test_case class test3d : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3d(mapnik::parameters const& params) test3d(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
std::deque<uint8_t> data(size_); {
for (std::size_t i=0;i<size_;++i) { std::deque<uint8_t> data(size_);
if (data[i] != 0) { for (std::size_t i = 0; i < size_; ++i)
throw std::runtime_error("found non zero value"); {
} if (data[i] != 0)
} {
} throw std::runtime_error("found non zero value");
return true; }
}
}
return true;
} }
}; };
class test4 : public benchmark::test_case class test4 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test4(mapnik::parameters const& params) test4(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
uint8_t *data = (uint8_t *)calloc(size_,sizeof(uint8_t)); {
ensure_zero(data,size_); uint8_t* data = (uint8_t*)calloc(size_, sizeof(uint8_t));
free(data); ensure_zero(data, size_);
} free(data);
return true; }
return true;
} }
}; };
class test5 : public benchmark::test_case class test5 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test5(mapnik::parameters const& params) test5(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
std::string data(array_.begin(),array_.end()); {
ensure_zero((uint8_t *)&data[0],size_); std::string data(array_.begin(), array_.end());
} ensure_zero((uint8_t*)&data[0], size_);
return true; }
return true;
} }
}; };
class test5b : public benchmark::test_case class test5b : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<char> array_; std::vector<char> array_;
test5b(mapnik::parameters const& params) test5b(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
std::string data(&array_[0],array_.size()); {
ensure_zero((uint8_t *)&data[0],size_); std::string data(&array_[0], array_.size());
} ensure_zero((uint8_t*)&data[0], size_);
return true; }
return true;
} }
}; };
@ -308,24 +300,23 @@ public:
class test6 : public benchmark::test_case class test6 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test6(mapnik::parameters const& params) test6(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
std::valarray<uint8_t> data(static_cast<uint8_t>(0),static_cast<size_t>(size_)); {
ensure_zero(&data[0],size_); std::valarray<uint8_t> data(static_cast<uint8_t>(0), static_cast<size_t>(size_));
} ensure_zero(&data[0], size_);
return true; }
return true;
} }
}; };
@ -335,24 +326,23 @@ public:
class test7 : public benchmark::test_case class test7 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test7(mapnik::parameters const& params) test7(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
boost::container::static_vector<uint8_t,256*256> data(size_,0); {
ensure_zero(&data[0],size_); boost::container::static_vector<uint8_t, 256 * 256> data(size_, 0);
} ensure_zero(&data[0], size_);
return true; }
return true;
} }
}; };
#endif #endif
@ -360,20 +350,20 @@ public:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.run<test4>("calloc") .run<test4>("calloc")
.run<test1>("malloc/memcpy") .run<test1>("malloc/memcpy")
.run<test1b>("malloc/memset") .run<test1b>("malloc/memset")
.run<test1c>("operator new/std::fill") .run<test1c>("operator new/std::fill")
.run<test2>("operator new/memcpy") .run<test2>("operator new/memcpy")
.run<test3>("vector(N)") .run<test3>("vector(N)")
.run<test3b>("vector/resize") .run<test3b>("vector/resize")
.run<test3c>("vector/assign") .run<test3c>("vector/assign")
.run<test3d>("deque(N)") .run<test3d>("deque(N)")
.run<test5>("std::string range") .run<test5>("std::string range")
.run<test5b>("std::string &[0]") .run<test5b>("std::string &[0]")
.run<test6>("valarray") .run<test6>("valarray")
#if BOOST_VERSION >= 105400 #if BOOST_VERSION >= 105400
.run<test7>("static_vector") .run<test7>("static_vector")
#endif #endif
.done(); .done();
} }

View file

@ -7,10 +7,12 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string expr_; std::string expr_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {} , expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))")
{}
bool validate() const bool validate() const
{ {
mapnik::expression_ptr expr = mapnik::parse_expression(expr_); mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
@ -18,24 +20,24 @@ public:
bool ret = (result == expr_); bool ret = (result == expr_);
if (!ret) if (!ret)
{ {
std::clog << result << " != " << expr_ << "\n"; std::clog << result << " != " << expr_ << "\n";
} }
return ret; return ret;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
mapnik::expression_ptr expr = mapnik::parse_expression(expr_); {
} mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
return true; }
return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
test test_runner(params); test test_runner(params);
return run(test_runner,"expr parsing"); return run(test_runner, "expr parsing");
} }

View file

@ -4,9 +4,10 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
{}
bool validate() const bool validate() const
{ {
std::size_t count = 0; std::size_t count = 0;
@ -22,14 +23,15 @@ public:
font_cache, font_cache,
mapnik::freetype_engine::get_mapping(), mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache()); mapnik::freetype_engine::get_cache());
if (f) ++count; if (f)
++count;
} }
return count == expected_count; return count == expected_count;
} }
bool operator()() const bool operator()() const
{ {
std::size_t expected_count = mapnik::freetype_engine::face_names().size(); std::size_t expected_count = mapnik::freetype_engine::face_names().size();
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
std::size_t count = 0; std::size_t count = 0;
mapnik::freetype_engine::font_file_mapping_type font_file_mapping; mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
@ -43,9 +45,11 @@ public:
font_cache, font_cache,
mapnik::freetype_engine::get_mapping(), mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache()); mapnik::freetype_engine::get_cache());
if (f) ++count; if (f)
++count;
} }
if (count != expected_count) { if (count != expected_count)
{
std::clog << "warning: face creation not working as expected\n"; std::clog << "warning: face creation not working as expected\n";
} }
} }
@ -56,14 +60,14 @@ public:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
bool success = mapnik::freetype_engine::register_fonts("./fonts", true); bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
if (!success) { if (!success)
std::clog << "warning, did not register any new fonts!\n"; {
return -1; std::clog << "warning, did not register any new fonts!\n";
} return -1;
}
std::size_t face_count = mapnik::freetype_engine::face_names().size(); std::size_t face_count = mapnik::freetype_engine::face_names().size();
test test_runner(params); test test_runner(params);
return run(test_runner,(boost::format("font_engine: creating %ld faces") % (face_count)).str()); return run(test_runner, (boost::format("font_engine: creating %ld faces") % (face_count)).str());
} }

View file

@ -5,17 +5,15 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
bool validate() const {}
{ bool validate() const { return mapnik::freetype_engine::register_fonts("./fonts", true); }
return mapnik::freetype_engine::register_fonts("./fonts", true);
}
bool operator()() const bool operator()() const
{ {
unsigned long count = 0; unsigned long count = 0;
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
mapnik::freetype_engine::register_fonts("./fonts", true); mapnik::freetype_engine::register_fonts("./fonts", true);
count++; count++;
@ -24,4 +22,4 @@ public:
} }
}; };
BENCHMARK(test,"font registration") BENCHMARK(test, "font registration")

View file

@ -1,22 +1,20 @@
#include "bench_framework.hpp" #include "bench_framework.hpp"
#include "../plugins/input/csv/csv_getline.hpp" #include "../plugins/input/csv/csv_getline.hpp"
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
std::string line_data_; std::string line_data_;
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
line_data_("this is one line\nand this is a second line\nand a third line") , 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"); boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data) if (line_data)
{ {
line_data_ = *line_data; line_data_ = *line_data;
} }
} }
bool validate() const bool validate() const
{ {
@ -25,14 +23,15 @@ public:
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; s << line_data_;
std::getline(s,csv_line,newline); std::getline(s, csv_line, newline);
if (csv_line != first) if (csv_line != first)
{ {
return true; return true;
} }
else 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; return true;
} }
@ -42,29 +41,28 @@ public:
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; s << line_data_;
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
std::getline(s,csv_line,newline); std::getline(s, csv_line, newline);
} }
return true; return true;
} }
}; };
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
public: public:
std::string line_data_; std::string line_data_;
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params), : test_case(params)
line_data_("this is one line\nand this is a second line\nand a third line") , 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"); boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data) if (line_data)
{ {
line_data_ = *line_data; line_data_ = *line_data;
} }
} }
bool validate() const bool validate() const
{ {
@ -74,14 +72,15 @@ public:
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; 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) if (csv_line != first)
{ {
return true; return true;
} }
else 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; return true;
} }
@ -92,9 +91,9 @@ public:
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; s << line_data_;
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
csv_utils::getline_csv(s,csv_line,newline,quote); csv_utils::getline_csv(s, csv_line, newline, quote);
} }
return true; return true;
} }
@ -106,17 +105,16 @@ int main(int argc, char** argv)
try try
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
{ {
test test_runner(params); test test_runner(params);
return_value = return_value | run(test_runner,"std::getline"); return_value = return_value | run(test_runner, "std::getline");
} }
{ {
test2 test_runner2(params); test2 test_runner2(params);
return_value = return_value | run(test_runner2,"csv_utils::getline_csv"); return_value = return_value | run(test_runner2, "csv_utils::getline_csv");
} }
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::clog << ex.what() << "\n"; std::clog << ex.what() << "\n";
return -1; return -1;

View file

@ -4,34 +4,32 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::vector<std::string> images_; std::vector<std::string> images_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
images_{ , images_{"./test/data/images/dummy.jpg",
"./test/data/images/dummy.jpg", "./test/data/images/dummy.jpeg",
"./test/data/images/dummy.jpeg", "./test/data/images/dummy.png",
"./test/data/images/dummy.png", "./test/data/images/dummy.tif",
"./test/data/images/dummy.tif", "./test/data/images/dummy.tiff",
"./test/data/images/dummy.tiff", //"./test/data/images/landusepattern.jpeg", // will fail since it is a png
//"./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/images/xcode-CgBI.png", // will fail since its an invalid png "./test/data/svg/octocat.svg",
"./test/data/svg/octocat.svg", "./test/data/svg/place-of-worship-24.svg",
"./test/data/svg/place-of-worship-24.svg", "./test/data/svg/point_sm.svg",
"./test/data/svg/point_sm.svg", "./test/data/svg/point.svg",
"./test/data/svg/point.svg", "./test/data/svg/airfield-12.svg"}
"./test/data/svg/airfield-12.svg" {}
} {} bool validate() const { return true; }
bool validate() const
{
return true;
}
bool operator()() const bool operator()() const
{ {
unsigned count = 0; unsigned count = 0;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
for (auto filename : images_) for (auto filename : images_)
{ {
auto marker = mapnik::marker_cache::instance().find(filename,true); auto marker = mapnik::marker_cache::instance().find(filename, true);
} }
++count; ++count;
} }
@ -39,4 +37,4 @@ public:
} }
}; };
BENCHMARK(test,"marker cache") BENCHMARK(test, "marker cache")

View file

@ -14,40 +14,38 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
{}
bool validate() const bool validate() const { return true; }
{
return true;
}
bool operator()() const bool operator()() const
{ {
mapnik::Map m(256,256,"epsg:3857"); mapnik::Map m(256, 256, "epsg:3857");
mapnik::parameters params; mapnik::parameters params;
params["type"]="memory"; params["type"] = "memory";
auto ds = std::make_shared<mapnik::memory_datasource>(params); auto ds = std::make_shared<mapnik::memory_datasource>(params);
// add whitespace to trigger phony "reprojection" // add whitespace to trigger phony "reprojection"
mapnik::layer lay("layer",m.srs() + " "); mapnik::layer lay("layer", m.srs() + " ");
lay.set_datasource(ds); lay.set_datasource(ds);
lay.add_style("style"); lay.add_style("style");
m.add_layer(lay); m.add_layer(lay);
// dummy style to ensure that layer is processed // 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 // dummy bbox, but "valid" because minx and miny are less
// with an invalid bbox then layer.visible() returns false // with an invalid bbox then layer.visible() returns false
// and the initial rendering setup is not run // and the initial rendering setup is not run
m.zoom_to_box(mapnik::box2d<double>(-1,-1,0,0)); m.zoom_to_box(mapnik::box2d<double>(-1, -1, 0, 0));
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
mapnik::image_rgba8 im(256,256); mapnik::image_rgba8 im(256, 256);
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im); mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
ren.apply(); ren.apply();
} }
return true; return true;
} }
}; };
BENCHMARK(test,"rendering with reprojection") BENCHMARK(test, "rendering with reprojection")

View file

@ -9,23 +9,25 @@ class test_static : public benchmark::test_case
{ {
double step_; double step_;
std::uint8_t start_; std::uint8_t start_;
public:
public:
test_static(mapnik::parameters const& params) test_static(mapnik::parameters const& params)
: test_case(params), : test_case(params)
step_(STEP_NUM), , step_(STEP_NUM)
start_(START_NUM) {} , start_(START_NUM)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
double value_ = 0.0; double value_ = 0.0;
std::uint8_t x; std::uint8_t x;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
double c = static_cast<double>(start_) * value_; double c = static_cast<double>(start_) * value_;
if (c >= 256.0) c = 255.0; if (c >= 256.0)
if (c < 0.0) c = 0.0; c = 255.0;
if (c < 0.0)
c = 0.0;
x = static_cast<std::uint8_t>(c); x = static_cast<std::uint8_t>(c);
value_ += step_; value_ += step_;
} }
@ -33,35 +35,34 @@ public:
} }
}; };
using boost::numeric::positive_overflow;
using boost::numeric::negative_overflow; using boost::numeric::negative_overflow;
using boost::numeric::positive_overflow;
class test_numeric : public benchmark::test_case class test_numeric : public benchmark::test_case
{ {
double step_; double step_;
std::uint8_t start_; std::uint8_t start_;
public:
public:
test_numeric(mapnik::parameters const& params) test_numeric(mapnik::parameters const& params)
: test_case(params), : test_case(params)
step_(STEP_NUM), , step_(STEP_NUM)
start_(START_NUM) {} , start_(START_NUM)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
double value_ = 0.0; double value_ = 0.0;
std::uint8_t x; std::uint8_t x;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
try { {
try
{
x = boost::numeric_cast<std::uint8_t>(start_ * value_); x = boost::numeric_cast<std::uint8_t>(start_ * value_);
} } catch (negative_overflow&)
catch(negative_overflow&)
{ {
x = std::numeric_limits<std::uint8_t>::min(); x = std::numeric_limits<std::uint8_t>::min();
} } catch (positive_overflow&)
catch(positive_overflow&)
{ {
x = std::numeric_limits<std::uint8_t>::max(); x = std::numeric_limits<std::uint8_t>::max();
} }
@ -73,8 +74,5 @@ public:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv).run<test_static>("static_cast").run<test_numeric>("numeric_cast").done();
.run<test_static>("static_cast")
.run<test_numeric>("numeric_cast")
.done();
} }

View file

@ -14,31 +14,36 @@ struct fake_path
cont_type::iterator itr_; cont_type::iterator itr_;
fake_path(std::initializer_list<double> l) fake_path(std::initializer_list<double> l)
: fake_path(l.begin(), l.size()) { : fake_path(l.begin(), l.size())
} {}
fake_path(std::vector<double> const &v) fake_path(std::vector<double> const& v)
: fake_path(v.begin(), v.size()) { : fake_path(v.begin(), v.size())
} {}
template <typename Itr> template<typename Itr>
fake_path(Itr itr, size_t sz) { fake_path(Itr itr, size_t sz)
{
size_t num_coords = sz >> 1; size_t num_coords = sz >> 1;
vertices_.reserve(num_coords); 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 x = *itr++;
double y = *itr++; double y = *itr++;
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO; unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
vertices_.push_back(std::make_tuple(x, y, cmd)); 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)); vertices_.push_back(std::make_tuple(x, y, cmd));
} }
itr_ = vertices_.begin(); itr_ = vertices_.begin();
} }
unsigned vertex(double *x, double *y) { unsigned vertex(double* x, double* y)
if (itr_ == vertices_.end()) { {
if (itr_ == vertices_.end())
{
return mapnik::SEG_END; return mapnik::SEG_END;
} }
*x = std::get<0>(*itr_); *x = std::get<0>(*itr_);
@ -48,33 +53,30 @@ struct fake_path
return cmd; return cmd;
} }
void rewind(unsigned) { void rewind(unsigned) { itr_ = vertices_.begin(); }
itr_ = vertices_.begin();
}
}; };
class test_offset : public benchmark::test_case class test_offset : public benchmark::test_case
{ {
public: public:
test_offset(mapnik::parameters const& params) test_offset(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
std::vector<double> path; std::vector<double> path;
int mysize = 2500; int mysize = 2500;
int x1 = 0; int x1 = 0;
path.reserve(mysize*2); path.reserve(mysize * 2);
for( int i = 0; i < mysize; i++ ) for (int i = 0; i < mysize; i++)
{ {
path.push_back( i ); path.push_back(i);
path.push_back( 0 ); path.push_back(0);
} }
fake_path fpath(path); fake_path fpath(path);
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
mapnik::offset_converter<fake_path> off_path(fpath); mapnik::offset_converter<fake_path> off_path(fpath);
off_path.set_offset(10); off_path.set_offset(10);
unsigned cmd; unsigned cmd;
@ -88,15 +90,14 @@ public:
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
int return_value = 0; int return_value = 0;
{ {
test_offset test_runner(params); test_offset test_runner(params);
return_value = run(test_runner,"offset_test"); return_value = run(test_runner, "offset_test");
} }
return return_value; return return_value;
} }

View file

@ -4,23 +4,23 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
mapnik::image_rgba8 im_; mapnik::image_rgba8 im_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
im_(256,256) {} , im_(256, 256)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
out.clear(); out.clear();
out = mapnik::save_to_string(im_,"png8:m=h:z=1"); out = mapnik::save_to_string(im_, "png8:m=h:z=1");
} }
return true; return true;
} }
}; };
BENCHMARK(test,"encoding blank png") BENCHMARK(test, "encoding blank png")

View file

@ -4,34 +4,37 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::shared_ptr<mapnik::image_rgba8> im_; std::shared_ptr<mapnik::image_rgba8> im_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) { : test_case(params)
{
std::string filename("./benchmark/data/multicolor.png"); std::string filename("./benchmark/data/multicolor.png");
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"png")); std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename, "png"));
if (!reader.get()) if (!reader.get())
{ {
throw mapnik::image_reader_exception("Failed to load: " + filename); throw mapnik::image_reader_exception("Failed to load: " + filename);
} }
im_ = std::make_shared<mapnik::image_rgba8>(reader->width(),reader->height()); im_ = std::make_shared<mapnik::image_rgba8>(reader->width(), reader->height());
reader->read(0,0,*im_); reader->read(0, 0, *im_);
} }
bool validate() const bool validate() const
{ {
std::string expected("./benchmark/data/multicolor-hextree-expected.png"); std::string expected("./benchmark/data/multicolor-hextree-expected.png");
std::string actual("./benchmark/data/multicolor-hextree-actual.png"); std::string actual("./benchmark/data/multicolor-hextree-actual.png");
mapnik::save_to_file(*im_,actual, "png8:m=h:z=1"); mapnik::save_to_file(*im_, actual, "png8:m=h:z=1");
return benchmark::compare_images(actual,expected); return benchmark::compare_images(actual, expected);
} }
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
out.clear(); out.clear();
out = mapnik::save_to_string(*im_,"png8:m=h:z=1"); out = mapnik::save_to_string(*im_, "png8:m=h:z=1");
} }
return true; return true;
} }
}; };
BENCHMARK(test,"encoding multicolor png") BENCHMARK(test, "encoding multicolor png")

View file

@ -39,30 +39,31 @@ void render(mapnik::geometry::multi_polygon<double> const& geom,
mapnik::box2d<double> const& extent, mapnik::box2d<double> const& extent,
std::string const& name) std::string const& name)
{ {
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::geometry::polygon_vertex_adapter<double>>; using path_type =
mapnik::transform_path_adapter<mapnik::view_transform, mapnik::geometry::polygon_vertex_adapter<double>>;
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>; using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>;
using renderer = agg::renderer_scanline_aa_solid<ren_base>; using renderer = agg::renderer_scanline_aa_solid<ren_base>;
mapnik::image_rgba8 im(256,256); mapnik::image_rgba8 im(256, 256);
mapnik::fill(im, mapnik::color("white")); mapnik::fill(im, mapnik::color("white"));
mapnik::box2d<double> padded_extent(155,134,665,466);//extent; mapnik::box2d<double> padded_extent(155, 134, 665, 466); // extent;
padded_extent.pad(10); padded_extent.pad(10);
mapnik::view_transform tr(im.width(),im.height(),padded_extent,0,0); 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::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size());
agg::pixfmt_rgba32_plain pixf(buf); agg::pixfmt_rgba32_plain pixf(buf);
ren_base renb(pixf); ren_base renb(pixf);
renderer ren(renb); renderer ren(renb);
mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"),mapnik::projection("epsg:4326")); mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"), mapnik::projection("epsg:4326"));
ren.color(agg::rgba8(127,127,127,255)); ren.color(agg::rgba8(127, 127, 127, 255));
agg::rasterizer_scanline_aa<> ras; agg::rasterizer_scanline_aa<> ras;
for (auto const& poly : geom) for (auto const& poly : geom)
{ {
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
path_type path(tr,va,prj_trans); path_type path(tr, va, prj_trans);
ras.add_path(path); ras.add_path(path);
} }
agg::scanline_u8 sl; agg::scanline_u8 sl;
agg::render_scanlines(ras, sl, ren); agg::render_scanlines(ras, sl, ren);
mapnik::save_to_file(im,name); mapnik::save_to_file(im, name);
} }
class test1 : public benchmark::test_case class test1 : public benchmark::test_case
@ -70,15 +71,15 @@ class test1 : public benchmark::test_case
std::string wkt_in_; std::string wkt_in_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public:
public:
using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>; using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>;
test1(mapnik::parameters const& params, test1(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
std::string const& wkt_in, : test_case(params)
mapnik::box2d<double> const& extent) , wkt_in_(wkt_in)
: test_case(params), , extent_(extent)
wkt_in_(wkt_in), , expected_("./benchmark/data/polygon_clipping_agg")
extent_(extent), {}
expected_("./benchmark/data/polygon_clipping_agg") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry<double> geom; mapnik::geometry::geometry<double> geom;
@ -99,14 +100,8 @@ public:
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
clipped.clip_box( clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
extent_.minx(),
extent_.miny(),
extent_.maxx(),
extent_.maxy());
clipped.rewind(0); clipped.rewind(0);
mapnik::geometry::polygon<double> poly2; mapnik::geometry::polygon<double> poly2;
@ -118,7 +113,8 @@ public:
{ {
if (cmd == mapnik::SEG_MOVETO) if (cmd == mapnik::SEG_MOVETO)
{ {
x0 = x; y0 = y; x0 = x;
y0 = y;
} }
if (cmd == mapnik::SEG_CLOSE) if (cmd == mapnik::SEG_CLOSE)
@ -126,7 +122,7 @@ public:
ring.emplace_back(x0, y0); ring.emplace_back(x0, y0);
break; break;
} }
ring.emplace_back(x,y); ring.emplace_back(x, y);
} }
poly2.push_back(std::move(ring)); poly2.push_back(std::move(ring));
// interior rings // interior rings
@ -135,30 +131,31 @@ public:
{ {
if (cmd == mapnik::SEG_MOVETO) if (cmd == mapnik::SEG_MOVETO)
{ {
x0 = x; y0 = y; x0 = x;
y0 = y;
} }
else if (cmd == mapnik::SEG_CLOSE) else if (cmd == mapnik::SEG_CLOSE)
{ {
ring.emplace_back(x0,y0); ring.emplace_back(x0, y0);
poly2.push_back(std::move(ring)); poly2.push_back(std::move(ring));
ring.clear(); ring.clear();
continue; continue;
} }
ring.emplace_back(x,y); ring.emplace_back(x, y);
} }
std::string expect = expected_+".png"; std::string expect = expected_ + ".png";
std::string actual = expected_+"_actual.png"; std::string actual = expected_ + "_actual.png";
mapnik::geometry::multi_polygon<double> mp; mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back(poly2); mp.emplace_back(poly2);
auto env = mapnik::geometry::envelope(mp); auto env = mapnik::geometry::envelope(mp);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{ {
std::clog << "generating expected image: " << expect << "\n"; std::clog << "generating expected image: " << expect << "\n";
render(mp,env,expect); render(mp, env, expect);
} }
render(mp,env,actual); render(mp, env, actual);
return benchmark::compare_images(actual,expect); return benchmark::compare_images(actual, expect);
} }
bool operator()() const bool operator()() const
{ {
@ -178,29 +175,28 @@ public:
return false; return false;
} }
bool valid = true; bool valid = true;
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
unsigned count = 0; unsigned count = 0;
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
clipped.clip_box( clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
extent_.minx(),
extent_.miny(),
extent_.maxx(),
extent_.maxy());
unsigned cmd; unsigned cmd;
double x,y; double x, y;
// NOTE: this rewind is critical otherwise // NOTE: this rewind is critical otherwise
// agg_conv_adapter_vpgen will give garbage // agg_conv_adapter_vpgen will give garbage
// values for the first vertex // values for the first vertex
clipped.rewind(0); clipped.rewind(0);
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) { while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END)
{
count++; count++;
} }
unsigned expected_count = 30; unsigned expected_count = 30;
if (count != expected_count) { if (count != expected_count)
std::clog << "test1: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; {
std::clog << "test1: clipping failed: processed " << count << " verticies but expected "
<< expected_count << "\n";
valid = false; valid = false;
} }
} }
@ -208,20 +204,19 @@ public:
} }
}; };
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
std::string wkt_in_; std::string wkt_in_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public:
test3(mapnik::parameters const& params, public:
std::string const& wkt_in, test3(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
mapnik::box2d<double> const& extent) : test_case(params)
: test_case(params), , wkt_in_(wkt_in)
wkt_in_(wkt_in), , extent_(extent)
extent_(extent), , expected_("./benchmark/data/polygon_clipping_boost")
expected_("./benchmark/data/polygon_clipping_boost") {} {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry<double> geom; mapnik::geometry::geometry<double> geom;
@ -234,12 +229,12 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon<double> >()) if (!geom.is<mapnik::geometry::polygon<double>>())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom); mapnik::geometry::polygon<double>& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
mapnik::geometry::linear_ring<double> bbox; mapnik::geometry::linear_ring<double> bbox;
@ -249,15 +244,15 @@ public:
bbox.emplace_back(extent_.maxx(), extent_.miny()); bbox.emplace_back(extent_.maxx(), extent_.miny());
bbox.emplace_back(extent_.minx(), extent_.miny()); bbox.emplace_back(extent_.minx(), extent_.miny());
std::deque<mapnik::geometry::polygon<double> > result; std::deque<mapnik::geometry::polygon<double>> result;
boost::geometry::intersection(bbox, poly, result); boost::geometry::intersection(bbox, poly, result);
std::string expect = expected_+".png"; std::string expect = expected_ + ".png";
std::string actual = expected_+"_actual.png"; std::string actual = expected_ + "_actual.png";
mapnik::geometry::multi_polygon<double> mp; mapnik::geometry::multi_polygon<double> 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); mp.emplace_back(_geom);
} }
mapnik::geometry::geometry<double> geom2(mp); mapnik::geometry::geometry<double> geom2(mp);
@ -265,10 +260,10 @@ public:
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{ {
std::clog << "generating expected image: " << expect << "\n"; std::clog << "generating expected image: " << expect << "\n";
render(mp,env,expect); render(mp, env, expect);
} }
render(mp,env,actual); render(mp, env, actual);
return benchmark::compare_images(actual,expect); return benchmark::compare_images(actual, expect);
} }
bool operator()() const bool operator()() const
{ {
@ -282,12 +277,12 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon<double> >()) if (!geom.is<mapnik::geometry::polygon<double>>())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom); mapnik::geometry::polygon<double>& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
mapnik::geometry::linear_ring<double> bbox; mapnik::geometry::linear_ring<double> bbox;
@ -298,22 +293,25 @@ public:
bbox.emplace_back(extent_.minx(), extent_.miny()); bbox.emplace_back(extent_.minx(), extent_.miny());
bool valid = true; bool valid = true;
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
std::deque<mapnik::geometry::polygon<double> > result; std::deque<mapnik::geometry::polygon<double>> result;
boost::geometry::intersection(bbox, poly, result); boost::geometry::intersection(bbox, poly, result);
unsigned count = 0; unsigned count = 0;
for (auto const& _geom : result) for (auto const& _geom : result)
{ {
mapnik::geometry::polygon_vertex_adapter<double> va(_geom); mapnik::geometry::polygon_vertex_adapter<double> va(_geom);
unsigned cmd; unsigned cmd;
double x,y; double x, y;
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) { while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END)
{
++count; ++count;
} }
unsigned expected_count = 29; unsigned expected_count = 29;
if (count != expected_count) { if (count != expected_count)
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; {
std::clog << "test3: clipping failed: processed " << count << " verticies but expected "
<< expected_count << "\n";
valid = false; valid = false;
} }
} }
@ -500,8 +498,8 @@ public:
} }
unsigned expected_count = 29; unsigned expected_count = 29;
if (count != expected_count) { if (count != expected_count) {
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; std::clog << "test3: clipping failed: processed " << count << " verticies but expected " <<
valid = false; expected_count << "\n"; valid = false;
} }
} }
} }
@ -513,13 +511,16 @@ public:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
// polygon/rect clipping // 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)) // IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134,
// RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) // 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
// OUT (expected) // 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)) // 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 #if 0
mapnik::box2d<double> clipping_box(181,106,631,470); mapnik::box2d<double> clipping_box(181,106,631,470);
std::string filename_("./benchmark/data/polygon.wkt"); std::string filename_("./benchmark/data/polygon.wkt");
@ -544,5 +545,5 @@ int main(int argc, char** argv)
} }
*/ */
#endif #endif
return 0;// return_value; return 0; // return_value;
} }

View file

@ -8,53 +8,51 @@ class test : public benchmark::test_case
{ {
std::string xml_; std::string xml_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
public:
test(mapnik::parameters const& params, public:
std::string const& xml, test(mapnik::parameters const& params, std::string const& xml, mapnik::box2d<double> const& extent)
mapnik::box2d<double> const& extent) : test_case(params)
: test_case(params), , xml_(xml)
xml_(xml), , extent_(extent)
extent_(extent) {}
{}
bool validate() const bool validate() const
{ {
mapnik::Map m(256,256); mapnik::Map m(256, 256);
mapnik::load_map(m,xml_); mapnik::load_map(m, xml_);
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
mapnik::image_rgba8 im(m.width(),m.height()); mapnik::image_rgba8 im(m.width(), m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im); mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
ren.apply(); ren.apply();
//mapnik::save_to_file(im.data(),"test.png"); // mapnik::save_to_file(im.data(),"test.png");
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
mapnik::Map m(256,256); mapnik::Map m(256, 256);
mapnik::load_map(m,xml_); mapnik::load_map(m, xml_);
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
mapnik::image_rgba8 im(m.width(),m.height()); mapnik::image_rgba8 im(m.width(), m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im); mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
ren.apply(); ren.apply();
} }
return true; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
mapnik::box2d<double> z1(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298); mapnik::box2d<double> z1(-20037508.3428, -8317435.0606, 20037508.3428, 18399242.7298);
// bbox for 16/10491/22911.png // bbox for 16/10491/22911.png
mapnik::box2d<double> z16(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214); mapnik::box2d<double> z16(-13622912.929097254, 6026906.8062295765, -13621689.93664469, 6028129.79868214);
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1) .run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1)
.run<test>("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1) .run<test>("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1)
.run<test>("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16) .run<test>("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16)
.run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16) .run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16)
.done(); .done();
} }

View file

@ -10,45 +10,46 @@ class test : public benchmark::test_case
mapnik::box2d<double> from_; mapnik::box2d<double> from_;
mapnik::box2d<double> to_; mapnik::box2d<double> to_;
bool defer_proj_init_; bool defer_proj_init_;
public:
public:
test(mapnik::parameters const& params, test(mapnik::parameters const& params,
std::string const& src, std::string const& src,
std::string const& dest, std::string const& dest,
mapnik::box2d<double> const& from, mapnik::box2d<double> const& from,
mapnik::box2d<double> const& to, mapnik::box2d<double> const& to,
bool defer_proj) bool defer_proj)
: test_case(params), : test_case(params)
src_(src), , src_(src)
dest_(dest), , dest_(dest)
from_(from), , from_(from)
to_(to), , to_(to)
defer_proj_init_(defer_proj) {} , defer_proj_init_(defer_proj)
{}
bool validate() const bool validate() const
{ {
mapnik::projection src(src_,defer_proj_init_); mapnik::projection src(src_, defer_proj_init_);
mapnik::projection dest(dest_,defer_proj_init_); mapnik::projection dest(dest_, defer_proj_init_);
mapnik::proj_transform tr(src,dest); mapnik::proj_transform tr(src, dest);
mapnik::box2d<double> bbox = from_; mapnik::box2d<double> bbox = from_;
if (!tr.forward(bbox)) return false; if (!tr.forward(bbox))
return ((std::fabs(bbox.minx() - to_.minx()) < .5) && return false;
(std::fabs(bbox.maxx() - to_.maxx()) < .5) && 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.miny() - to_.miny()) < .5) && (std::fabs(bbox.maxy() - to_.maxy()) < .5));
(std::fabs(bbox.maxy() - to_.maxy()) < .5)
);
} }
bool operator()() const bool operator()() const
{ {
mapnik::projection src(src_,defer_proj_init_); mapnik::projection src(src_, defer_proj_init_);
mapnik::projection dest(dest_,defer_proj_init_); mapnik::projection dest(dest_, defer_proj_init_);
mapnik::proj_transform tr(src,dest); mapnik::proj_transform tr(src, dest);
for (std::size_t i=0;i<iterations_;++i) for (std::size_t i = 0; i < iterations_; ++i)
{ {
for (int j=-180;j<180;j=j+5) for (int j = -180; j < 180; j = j + 5)
{ {
for (int k=-85;k<85;k=k+5) for (int k = -85; k < 85; k = k + 5)
{ {
mapnik::box2d<double> box(j,k,j,k); mapnik::box2d<double> box(j, k, j, k);
if (!tr.forward(box)) throw std::runtime_error("could not transform coords"); 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 // echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::box2d<double> from(-180,-80,180,80); mapnik::box2d<double> from(-180, -80, 180, 80);
mapnik::box2d<double> to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316); mapnik::box2d<double> to(-20037508.3427892476, -15538711.0963092316, 20037508.3427892476, 15538711.0963092316);
std::string from_str("epsg:4326"); std::string from_str("epsg:4326");
std::string to_str("epsg:3857"); std::string to_str("epsg:3857");
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"); 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) return benchmark::sequencer(argc, argv)
.run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true) .run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true)
.run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true) .run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true)
.run<test>("merc->lonlat epsg (internal)", to_str, from_str, to, from, true) .run<test>("merc->lonlat epsg (internal)", to_str, from_str, to, from, true)
.run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true) .run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true)
.done(); .done();
} }

View file

@ -6,43 +6,41 @@ using quad_tree_type = mapnik::quad_tree<std::size_t>;
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
{}
bool validate() const bool validate() const { return true; }
{
return true;
}
bool operator()() const bool operator()() const
{ {
std::random_device rd; std::random_device rd;
std::default_random_engine engine(rd()); std::default_random_engine engine(rd());
std::uniform_int_distribution<int> uniform_dist(0, 2048); std::uniform_int_distribution<int> uniform_dist(0, 2048);
quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048)); quad_tree_type tree(mapnik::box2d<double>(0, 0, 2048, 2048));
//populate // populate
for (size_t i = 0; i < iterations_; ++i) for (size_t i = 0; i < iterations_; ++i)
{ {
int cx = uniform_dist(engine); int cx = uniform_dist(engine);
int cy = uniform_dist(engine); int cy = uniform_dist(engine);
int sx = 0.2 * uniform_dist(engine); int sx = 0.2 * uniform_dist(engine);
int sy = 0.2 * uniform_dist(engine); int sy = 0.2 * uniform_dist(engine);
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy); mapnik::box2d<double> box(cx - sx, cy - sy, cx + sx, cy + sy);
tree.insert(i, box); tree.insert(i, box);
} }
// bounding box query // bounding box query
std::size_t count=0; std::size_t count = 0;
for (size_t i = 0; i < iterations_; ++i) for (size_t i = 0; i < iterations_; ++i)
{ {
int cx = uniform_dist(engine); int cx = uniform_dist(engine);
int cy = uniform_dist(engine); int cy = uniform_dist(engine);
int sx = 0.4 * uniform_dist(engine); int sx = 0.4 * uniform_dist(engine);
int sy = 0.4 * uniform_dist(engine); int sy = 0.4 * uniform_dist(engine);
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy); mapnik::box2d<double> box(cx - sx, cy - sy, cx + sx, cy + sy);
auto itr = tree.query_in_box(box); auto itr = tree.query_in_box(box);
auto end = tree.query_end(); auto end = tree.query_end();
for ( ;itr != end; ++itr) for (; itr != end; ++itr)
{ {
++count; ++count;
} }
@ -51,4 +49,4 @@ public:
} }
}; };
BENCHMARK(test,"quad_tree creation") BENCHMARK(test, "quad_tree creation")

View file

@ -15,16 +15,17 @@ class test : public benchmark::test_case
mapnik::value_integer height_; mapnik::value_integer height_;
double scale_factor_; double scale_factor_;
std::string preview_; std::string preview_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
xml_(), , xml_()
extent_(), , extent_()
width_(*params.get<mapnik::value_integer>("width",256)), , width_(*params.get<mapnik::value_integer>("width", 256))
height_(*params.get<mapnik::value_integer>("height",256)), , height_(*params.get<mapnik::value_integer>("height", 256))
scale_factor_(*params.get<mapnik::value_double>("scale_factor",1.0)), , scale_factor_(*params.get<mapnik::value_double>("scale_factor", 1.0))
preview_(*params.get<std::string>("preview","")) , preview_(*params.get<std::string>("preview", ""))
{ {
boost::optional<std::string> map = params.get<std::string>("map"); boost::optional<std::string> map = params.get<std::string>("map");
if (!map) if (!map)
{ {
@ -43,70 +44,75 @@ public:
{ {
throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg"); throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg");
}*/ }*/
}
}
bool validate() const bool validate() const
{ {
mapnik::Map m(width_,height_); mapnik::Map m(width_, height_);
mapnik::load_map(m,xml_,true); mapnik::load_map(m, xml_, true);
if (extent_.valid()) { if (extent_.valid())
{
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
} else { }
else
{
m.zoom_all(); m.zoom_all();
} }
mapnik::image_rgba8 im(m.width(),m.height()); mapnik::image_rgba8 im(m.width(), m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
ren.apply(); ren.apply();
if (!preview_.empty()) { if (!preview_.empty())
{
std::clog << "preview available at " << preview_ << "\n"; std::clog << "preview available at " << preview_ << "\n";
mapnik::save_to_file(im,preview_); mapnik::save_to_file(im, preview_);
} }
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
if (!preview_.empty()) { if (!preview_.empty())
{
return false; return false;
} }
mapnik::Map m(width_,height_); mapnik::Map m(width_, height_);
mapnik::load_map(m,xml_); mapnik::load_map(m, xml_);
if (extent_.valid()) { if (extent_.valid())
{
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
} else { }
else
{
m.zoom_all(); m.zoom_all();
} }
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
mapnik::image_rgba8 im(m.width(),m.height()); mapnik::image_rgba8 im(m.width(), m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
ren.apply(); ren.apply();
} }
return true; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int return_value = 0; int return_value = 0;
try try
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
boost::optional<std::string> name = params.get<std::string>("name"); boost::optional<std::string> name = params.get<std::string>("name");
if (!name) if (!name)
{ {
std::clog << "please provide a name for this test\n"; std::clog << "please provide a name for this test\n";
return -1; return -1;
} }
mapnik::freetype_engine::register_fonts("./fonts/",true); mapnik::freetype_engine::register_fonts("./fonts/", true);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
{ {
test test_runner(params); 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"; std::clog << ex.what() << "\n";
return -1; return -1;

View file

@ -12,14 +12,15 @@
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <stdexcept> #include <stdexcept>
template <typename Renderer> void process_layers(Renderer & ren, template<typename Renderer>
mapnik::request const& m_req, void process_layers(Renderer& ren,
mapnik::projection const& map_proj, mapnik::request const& m_req,
std::vector<mapnik::layer> const& layers, mapnik::projection const& map_proj,
double scale_denom) std::vector<mapnik::layer> const& layers,
double scale_denom)
{ {
unsigned layers_size = layers.size(); 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]; mapnik::layer const& lyr = layers[i];
if (lyr.visible(scale_denom)) if (lyr.visible(scale_denom))
@ -50,17 +51,18 @@ class test : public benchmark::test_case
double scale_factor_; double scale_factor_;
std::string preview_; std::string preview_;
mutable mapnik::image_rgba8 im_; mutable mapnik::image_rgba8 im_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
xml_(), , xml_()
extent_(), , extent_()
width_(*params.get<mapnik::value_integer>("width",256)), , width_(*params.get<mapnik::value_integer>("width", 256))
height_(*params.get<mapnik::value_integer>("height",256)), , height_(*params.get<mapnik::value_integer>("height", 256))
m_(new mapnik::Map(width_,height_)), , m_(new mapnik::Map(width_, height_))
scale_factor_(*params.get<mapnik::value_double>("scale_factor",2.0)), , scale_factor_(*params.get<mapnik::value_double>("scale_factor", 2.0))
preview_(*params.get<std::string>("preview","")), , preview_(*params.get<std::string>("preview", ""))
im_(m_->width(),m_->height()) , im_(m_->width(), m_->height())
{ {
boost::optional<std::string> map = params.get<std::string>("map"); boost::optional<std::string> map = params.get<std::string>("map");
if (!map) if (!map)
@ -70,7 +72,7 @@ public:
xml_ = *map; xml_ = *map;
boost::optional<std::string> ext = params.get<std::string>("extent"); boost::optional<std::string> ext = params.get<std::string>("extent");
mapnik::load_map(*m_,xml_,true); mapnik::load_map(*m_, xml_, true);
if (ext && !ext->empty()) if (ext && !ext->empty())
{ {
if (!extent_.from_string(*ext)) if (!extent_.from_string(*ext))
@ -87,42 +89,44 @@ public:
bool validate() const bool validate() const
{ {
mapnik::request m_req(width_,height_,extent_); mapnik::request m_req(width_, height_, extent_);
mapnik::attributes variables; mapnik::attributes variables;
m_req.set_buffer_size(m_->buffer_size()); m_req.set_buffer_size(m_->buffer_size());
mapnik::projection map_proj(m_->srs(),true); mapnik::projection map_proj(m_->srs(), true);
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic()); double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic());
scale_denom *= scale_factor_; scale_denom *= scale_factor_;
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_,m_req,variables,im_,scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_, m_req, variables, im_, scale_factor_);
ren.start_map_processing(*m_); ren.start_map_processing(*m_);
std::vector<mapnik::layer> const& layers = m_->layers(); std::vector<mapnik::layer> 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_); ren.end_map_processing(*m_);
if (!preview_.empty()) { if (!preview_.empty())
{
std::clog << "preview available at " << preview_ << "\n"; std::clog << "preview available at " << preview_ << "\n";
mapnik::save_to_file(im_,preview_); mapnik::save_to_file(im_, preview_);
} }
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
if (!preview_.empty()) { if (!preview_.empty())
{
return false; return false;
} }
for (unsigned i=0;i<iterations_;++i) for (unsigned i = 0; i < iterations_; ++i)
{ {
mapnik::request m_req(width_,height_,extent_); mapnik::request m_req(width_, height_, extent_);
mapnik::image_rgba8 im(m_->width(),m_->height()); mapnik::image_rgba8 im(m_->width(), m_->height());
mapnik::attributes variables; mapnik::attributes variables;
m_req.set_buffer_size(m_->buffer_size()); m_req.set_buffer_size(m_->buffer_size());
mapnik::projection map_proj(m_->srs(),true); mapnik::projection map_proj(m_->srs(), true);
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic()); double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic());
scale_denom *= scale_factor_; scale_denom *= scale_factor_;
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_,m_req,variables,im,scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_, m_req, variables, im, scale_factor_);
ren.start_map_processing(*m_); ren.start_map_processing(*m_);
std::vector<mapnik::layer> const& layers = m_->layers(); std::vector<mapnik::layer> 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_); ren.end_map_processing(*m_);
bool diff = false; bool diff = false;
mapnik::image_rgba8 const& dest = im; mapnik::image_rgba8 const& dest = im;
@ -133,37 +137,37 @@ public:
const unsigned int* row_to = dest.get_row(y); const unsigned int* row_to = dest.get_row(y);
for (unsigned int x = 0; x < width_; ++x) 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; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int return_value = 0; int return_value = 0;
try try
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
boost::optional<std::string> name = params.get<std::string>("name"); boost::optional<std::string> name = params.get<std::string>("name");
if (!name) if (!name)
{ {
std::clog << "please provide a name for this test\n"; std::clog << "please provide a name for this test\n";
return -1; return -1;
} }
mapnik::freetype_engine::register_fonts("./fonts/",true); mapnik::freetype_engine::register_fonts("./fonts/", true);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
{ {
test test_runner(params); 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"; std::clog << ex.what() << "\n";
return -1; return -1;

View file

@ -4,27 +4,31 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_("true") {} , value_("true")
{}
bool validate() const bool validate() const
{ {
bool result = false; bool result = false;
mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result); mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);
if (!result) return result; if (!result)
mapnik::util::string2bool(value_,result); return result;
mapnik::util::string2bool(value_, result);
return (result == true); return (result == true);
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
bool result = false; bool result = false;
mapnik::util::string2bool(value_,result); mapnik::util::string2bool(value_, result);
mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result); mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);
} }
return true; return true;
} }
}; };
BENCHMARK(test,"string->bool") BENCHMARK(test, "string->bool")

View file

@ -4,29 +4,36 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_("1.23456789") {} , value_("1.23456789")
{}
bool validate() const bool validate() const
{ {
double result = 0; double result = 0;
if (!mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result)) return false; if (!mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result))
if (result != 1.23456789) return false; return false;
if (result != 1.23456789)
return false;
result = 0; result = 0;
if (!mapnik::util::string2double(value_,result)) return false; if (!mapnik::util::string2double(value_, result))
if (result != 1.23456789) return false; return false;
if (result != 1.23456789)
return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
double result = 0; double result = 0;
mapnik::util::string2double(value_,result); mapnik::util::string2double(value_, result);
mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result); mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result);
} }
return true; return true;
} }
}; };
BENCHMARK(test,"string->double") BENCHMARK(test, "string->double")

View file

@ -4,29 +4,36 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_("123456789") {} , value_("123456789")
{}
bool validate() const bool validate() const
{ {
mapnik::value_integer result = 0; mapnik::value_integer result = 0;
if (!mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result)) return false; if (!mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result))
if (result != 123456789) return false; return false;
if (result != 123456789)
return false;
result = 0; result = 0;
if (!mapnik::util::string2int(value_,result)) return false; if (!mapnik::util::string2int(value_, result))
if (result != 123456789) return false; return false;
if (result != 123456789)
return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
mapnik::value_integer result = 0; mapnik::value_integer result = 0;
mapnik::util::string2int(value_,result); mapnik::util::string2int(value_, result);
mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result); mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result);
} }
return true; return true;
} }
}; };
BENCHMARK(test,"string->int") BENCHMARK(test, "string->int")

View file

@ -4,25 +4,28 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
double value_; double value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_(-0.1234) {} , value_(-0.1234)
{}
bool validate() const bool validate() const
{ {
std::string s; std::string s;
mapnik::util::to_string(s,value_); mapnik::util::to_string(s, value_);
return (s == "-0.1234"); return (s == "-0.1234");
} }
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
out.clear(); out.clear();
mapnik::util::to_string(out,value_); mapnik::util::to_string(out, value_);
} }
return true; return true;
} }
}; };
BENCHMARK(test,"to_string double->string") BENCHMARK(test, "to_string double->string")

View file

@ -4,10 +4,12 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
double value_; double value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_(-0.1234) {} , value_(-0.1234)
{}
bool validate() const bool validate() const
{ {
std::ostringstream s; std::ostringstream s;
@ -17,7 +19,8 @@ public:
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::ostringstream s; std::ostringstream s;
s << value_; s << value_;
out = s.str(); out = s.str();
@ -26,4 +29,4 @@ public:
} }
}; };
BENCHMARK(test,"ostringstream double->string") BENCHMARK(test, "ostringstream double->string")

View file

@ -13,27 +13,29 @@ using mapnik::util::from_u8string;
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
utf8_(from_u8string(u8"שלום")) {} , utf8_(from_u8string(u8"שלום"))
{}
bool validate() const bool validate() const
{ {
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv; std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
std::u32string utf32 = utf32conv.from_bytes(utf8_); std::u32string utf32 = utf32conv.from_bytes(utf8_);
if (utf32.size() != 4) return false; if (utf32.size() != 4)
if (utf32[0] != 0x5e9 && return false;
utf32[1] != 0x5dc && if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
utf32[2] != 0x5d5 && return false;
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
std::u32string utf32; std::u32string utf32;
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv; std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
utf32 = utf32conv.from_bytes(utf8_); {
utf32 = utf32conv.from_bytes(utf8_);
} }
return true; return true;
} }
@ -44,26 +46,28 @@ public:
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public:
public:
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params), : test_case(params)
utf8_(from_u8string(u8"שלום")) {} , utf8_(from_u8string(u8"שלום"))
{}
bool validate() const bool validate() const
{ {
std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
if (utf32.size() != 4) return false; if (utf32.size() != 4)
if (utf32[0] != 0x5e9 && return false;
utf32[1] != 0x5dc && if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
utf32[2] != 0x5d5 && return false;
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
std::u32string utf32; std::u32string utf32;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); {
} utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
}
return true; return true;
} }
}; };
@ -71,28 +75,30 @@ public:
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public:
public:
test3(mapnik::parameters const& params) test3(mapnik::parameters const& params)
: test_case(params), : test_case(params)
utf8_(from_u8string(u8"שלום")) {} , utf8_(from_u8string(u8"שלום"))
{}
bool validate() const bool validate() const
{ {
mapnik::transcoder tr_("utf-8"); mapnik::transcoder tr_("utf-8");
mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(),utf8_.size()); mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(), utf8_.size());
//std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); // std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
if (utf32.length() != 4) return false; if (utf32.length() != 4)
if (utf32[0] != 0x5e9 && return false;
utf32[1] != 0x5dc && if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
utf32[2] != 0x5d5 && return false;
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
mapnik::transcoder tr_("utf-8"); mapnik::transcoder tr_("utf-8");
mapnik::value_unicode_string utf32; mapnik::value_unicode_string utf32;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
utf32 = tr_.transcode(utf8_.data(),utf8_.size()); {
utf32 = tr_.transcode(utf8_.data(), utf8_.size());
} }
return true; return true;
} }
@ -101,17 +107,17 @@ public:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc,argv,params); benchmark::handle_args(argc, argv, params);
int return_value = 0; int return_value = 0;
#ifndef __linux__ #ifndef __linux__
test test_runner(params); test test_runner(params);
return_value = return_value | run(test_runner,"utf encode std::codecvt"); return_value = return_value | run(test_runner, "utf encode std::codecvt");
#else #else
std::clog << "skipping 'utf encode std::codecvt' test since <codecvt> is not supported on __linux__\n"; std::clog << "skipping 'utf encode std::codecvt' test since <codecvt> is not supported on __linux__\n";
#endif #endif
test2 test_runner2(params); 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); 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; return return_value;
} }

View file

@ -2,16 +2,12 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
bool validate() const {}
{ bool validate() const { return true; }
return true; void operator()() const {}
}
void operator()() const
{
}
}; };
BENCHMARK(test,"test name") BENCHMARK(test, "test name")