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

View file

@ -5,32 +5,31 @@
#include <mapnik/image_util.hpp>
#include <mapnik/image_reader.hpp>
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"));
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;
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;
}
} // namespace benchmark
#endif // MAPNIK_COMPARE_IMAGES_HPP

View file

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

View file

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

View file

@ -7,10 +7,12 @@
class test : public benchmark::test_case
{
std::string expr_;
public:
public:
test(mapnik::parameters const& params)
: test_case(params),
expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {}
: test_case(params)
, expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))")
{}
bool validate() const
{
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
@ -18,24 +20,24 @@ public:
bool ret = (result == expr_);
if (!ret)
{
std::clog << result << " != " << expr_ << "\n";
std::clog << result << " != " << expr_ << "\n";
}
return ret;
}
bool operator()() const
{
for (std::size_t i=0;i<iterations_;++i) {
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
}
return true;
for (std::size_t i = 0; i < iterations_; ++i)
{
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
}
return true;
}
};
int main(int argc, char** argv)
{
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
benchmark::handle_args(argc, argv, 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
{
public:
public:
test(mapnik::parameters const& params)
: test_case(params) {}
: test_case(params)
{}
bool validate() const
{
std::size_t count = 0;
@ -22,14 +23,15 @@ public:
font_cache,
mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache());
if (f) ++count;
if (f)
++count;
}
return count == expected_count;
}
bool operator()() const
{
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;
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
@ -43,9 +45,11 @@ public:
font_cache,
mapnik::freetype_engine::get_mapping(),
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";
}
}
@ -56,14 +60,14 @@ public:
int main(int argc, char** argv)
{
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
benchmark::handle_args(argc, argv, params);
bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
if (!success) {
std::clog << "warning, did not register any new fonts!\n";
return -1;
if (!success)
{
std::clog << "warning, did not register any new fonts!\n";
return -1;
}
std::size_t face_count = mapnik::freetype_engine::face_names().size();
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
{
public:
public:
test(mapnik::parameters const& params)
: test_case(params) {}
bool validate() const
{
return mapnik::freetype_engine::register_fonts("./fonts", true);
}
: test_case(params)
{}
bool validate() const { return mapnik::freetype_engine::register_fonts("./fonts", true); }
bool operator()() const
{
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);
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 "../plugins/input/csv/csv_getline.hpp"
class test : public benchmark::test_case
{
public:
public:
std::string line_data_;
test(mapnik::parameters const& params)
: test_case(params),
line_data_("this is one line\nand this is a second line\nand a third line")
{
boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data)
{
line_data_ = *line_data;
}
}
: test_case(params)
, line_data_("this is one line\nand this is a second line\nand a third line")
{
boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data)
{
line_data_ = *line_data;
}
}
bool validate() const
{
@ -25,14 +23,15 @@ public:
std::string csv_line;
std::stringstream s;
s << line_data_;
std::getline(s,csv_line,newline);
std::getline(s, csv_line, newline);
if (csv_line != first)
{
return true;
}
else
{
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line ("
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
}
return true;
}
@ -42,29 +41,28 @@ public:
std::string csv_line;
std::stringstream s;
s << line_data_;
for (unsigned i=0;i<iterations_;++i)
for (unsigned i = 0; i < iterations_; ++i)
{
std::getline(s,csv_line,newline);
std::getline(s, csv_line, newline);
}
return true;
}
};
class test2 : public benchmark::test_case
{
public:
public:
std::string line_data_;
test2(mapnik::parameters const& params)
: test_case(params),
line_data_("this is one line\nand this is a second line\nand a third line")
{
boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data)
{
line_data_ = *line_data;
}
}
: test_case(params)
, line_data_("this is one line\nand this is a second line\nand a third line")
{
boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data)
{
line_data_ = *line_data;
}
}
bool validate() const
{
@ -74,14 +72,15 @@ public:
std::string csv_line;
std::stringstream s;
s << line_data_;
csv_utils::getline_csv(s,csv_line,newline,quote);
csv_utils::getline_csv(s, csv_line, newline, quote);
if (csv_line != first)
{
return true;
}
else
{
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line ("
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
}
return true;
}
@ -92,9 +91,9 @@ public:
std::string csv_line;
std::stringstream s;
s << line_data_;
for (unsigned i=0;i<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;
}
@ -106,17 +105,16 @@ int main(int argc, char** argv)
try
{
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
benchmark::handle_args(argc, argv, 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);
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";
return -1;

View file

@ -4,34 +4,32 @@
class test : public benchmark::test_case
{
std::vector<std::string> images_;
public:
public:
test(mapnik::parameters const& params)
: test_case(params),
images_{
"./test/data/images/dummy.jpg",
"./test/data/images/dummy.jpeg",
"./test/data/images/dummy.png",
"./test/data/images/dummy.tif",
"./test/data/images/dummy.tiff",
//"./test/data/images/landusepattern.jpeg", // will fail since it is a png
//"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png
"./test/data/svg/octocat.svg",
"./test/data/svg/place-of-worship-24.svg",
"./test/data/svg/point_sm.svg",
"./test/data/svg/point.svg",
"./test/data/svg/airfield-12.svg"
} {}
bool validate() const
{
return true;
}
: test_case(params)
, images_{"./test/data/images/dummy.jpg",
"./test/data/images/dummy.jpeg",
"./test/data/images/dummy.png",
"./test/data/images/dummy.tif",
"./test/data/images/dummy.tiff",
//"./test/data/images/landusepattern.jpeg", // will fail since it is a png
//"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png
"./test/data/svg/octocat.svg",
"./test/data/svg/place-of-worship-24.svg",
"./test/data/svg/point_sm.svg",
"./test/data/svg/point.svg",
"./test/data/svg/airfield-12.svg"}
{}
bool validate() const { return true; }
bool operator()() const
{
unsigned count = 0;
for (std::size_t i=0;i<iterations_;++i) {
for (std::size_t i = 0; i < iterations_; ++i)
{
for (auto filename : images_)
{
auto marker = mapnik::marker_cache::instance().find(filename,true);
auto marker = mapnik::marker_cache::instance().find(filename, true);
}
++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
{
public:
public:
test(mapnik::parameters const& params)
: test_case(params) {}
: test_case(params)
{}
bool validate() const
{
return true;
}
bool validate() const { return true; }
bool operator()() const
{
mapnik::Map m(256,256,"epsg:3857");
mapnik::Map m(256, 256, "epsg:3857");
mapnik::parameters params;
params["type"]="memory";
params["type"] = "memory";
auto ds = std::make_shared<mapnik::memory_datasource>(params);
// add whitespace to trigger phony "reprojection"
mapnik::layer lay("layer",m.srs() + " ");
mapnik::layer lay("layer", m.srs() + " ");
lay.set_datasource(ds);
lay.add_style("style");
m.add_layer(lay);
// dummy style to ensure that layer is processed
m.insert_style("style",mapnik::feature_type_style());
m.insert_style("style", mapnik::feature_type_style());
// dummy bbox, but "valid" because minx and miny are less
// with an invalid bbox then layer.visible() returns false
// and the initial rendering setup is not run
m.zoom_to_box(mapnik::box2d<double>(-1,-1,0,0));
for (unsigned i=0;i<iterations_;++i)
m.zoom_to_box(mapnik::box2d<double>(-1, -1, 0, 0));
for (unsigned i = 0; i < iterations_; ++i)
{
mapnik::image_rgba8 im(256,256);
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
mapnik::image_rgba8 im(256, 256);
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
ren.apply();
}
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_;
std::uint8_t start_;
public:
public:
test_static(mapnik::parameters const& params)
: test_case(params),
step_(STEP_NUM),
start_(START_NUM) {}
bool validate() const
{
return true;
}
: test_case(params)
, step_(STEP_NUM)
, start_(START_NUM)
{}
bool validate() const { return true; }
bool operator()() const
{
double value_ = 0.0;
std::uint8_t x;
for (std::size_t i=0;i<iterations_;++i) {
for (std::size_t i = 0; i < iterations_; ++i)
{
double c = static_cast<double>(start_) * value_;
if (c >= 256.0) c = 255.0;
if (c < 0.0) c = 0.0;
if (c >= 256.0)
c = 255.0;
if (c < 0.0)
c = 0.0;
x = static_cast<std::uint8_t>(c);
value_ += step_;
}
@ -33,35 +35,34 @@ public:
}
};
using boost::numeric::positive_overflow;
using boost::numeric::negative_overflow;
using boost::numeric::positive_overflow;
class test_numeric : public benchmark::test_case
{
double step_;
std::uint8_t start_;
public:
public:
test_numeric(mapnik::parameters const& params)
: test_case(params),
step_(STEP_NUM),
start_(START_NUM) {}
bool validate() const
{
return true;
}
: test_case(params)
, step_(STEP_NUM)
, start_(START_NUM)
{}
bool validate() const { return true; }
bool operator()() const
{
double value_ = 0.0;
std::uint8_t x;
for (std::size_t i=0;i<iterations_;++i) {
try {
for (std::size_t i = 0; i < iterations_; ++i)
{
try
{
x = boost::numeric_cast<std::uint8_t>(start_ * value_);
}
catch(negative_overflow&)
} catch (negative_overflow&)
{
x = std::numeric_limits<std::uint8_t>::min();
}
catch(positive_overflow&)
} catch (positive_overflow&)
{
x = std::numeric_limits<std::uint8_t>::max();
}
@ -73,8 +74,5 @@ public:
int main(int argc, char** argv)
{
return benchmark::sequencer(argc, argv)
.run<test_static>("static_cast")
.run<test_numeric>("numeric_cast")
.done();
return benchmark::sequencer(argc, argv).run<test_static>("static_cast").run<test_numeric>("numeric_cast").done();
}

View file

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

View file

@ -4,23 +4,23 @@
class test : public benchmark::test_case
{
mapnik::image_rgba8 im_;
public:
public:
test(mapnik::parameters const& params)
: test_case(params),
im_(256,256) {}
bool validate() const
{
return true;
}
: test_case(params)
, im_(256, 256)
{}
bool validate() const { return true; }
bool operator()() const
{
std::string out;
for (std::size_t i=0;i<iterations_;++i) {
for (std::size_t i = 0; i < iterations_; ++i)
{
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;
}
};
BENCHMARK(test,"encoding blank png")
BENCHMARK(test, "encoding blank png")

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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