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

@ -34,24 +34,16 @@ protected:
mapnik::parameters params_;
std::size_t threads_;
std::size_t iterations_;
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)))
: 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_;
}
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;
};
@ -61,19 +53,23 @@ public:
// or negated index of an ill-formed option argument
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,8 +110,7 @@ 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";
}
}
@ -133,14 +132,13 @@ inline int handle_args(int argc, char** argv, mapnik::parameters & params)
auto result = run(test_runner, name); \
testing::run_cleanup(); \
return result; \
} \
catch (std::exception const& ex) \
} 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;
@ -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);
@ -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),
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);
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;
@ -272,10 +278,7 @@ struct sequencer
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)
@ -292,6 +295,6 @@ protected:
int exit_code_;
};
}
} // namespace benchmark
#endif // MAPNIK_BENCH_FRAMEWORK_HPP

View file

@ -5,7 +5,6 @@
#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)
@ -31,6 +30,6 @@ namespace benchmark {
return compare(dest, src, 0, true) == 0;
}
}
} // namespace benchmark
#endif // MAPNIK_COMPARE_IMAGES_HPP

View file

@ -9,7 +9,10 @@ struct bench_func : benchmark::test_case
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; }
@ -23,8 +26,7 @@ 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)
{

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
@ -34,16 +38,15 @@ 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) {
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_);
@ -60,16 +63,15 @@ 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) {
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_);
@ -86,16 +88,15 @@ 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) {
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_);
@ -105,23 +106,21 @@ public:
}
};
class test2 : public benchmark::test_case
{
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) {
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_);
@ -137,16 +136,15 @@ 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) {
for (std::size_t i = 0; i < iterations_; ++i)
{
std::vector<uint8_t> data(size_);
ensure_zero(&data[0], data.size());
}
@ -154,23 +152,21 @@ public:
}
};
class test3b : public benchmark::test_case
{
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) {
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());
@ -179,23 +175,21 @@ public:
}
};
class test3c : public benchmark::test_case
{
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) {
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());
@ -210,19 +204,20 @@ 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) {
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) {
for (std::size_t i = 0; i < size_; ++i)
{
if (data[i] != 0)
{
throw std::runtime_error("found non zero value");
}
}
@ -237,16 +232,15 @@ 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) {
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);
@ -261,16 +255,15 @@ 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) {
for (std::size_t i = 0; i < iterations_; ++i)
{
std::string data(array_.begin(), array_.end());
ensure_zero((uint8_t*)&data[0], size_);
}
@ -284,16 +277,15 @@ 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) {
for (std::size_t i = 0; i < iterations_; ++i)
{
std::string data(&array_[0], array_.size());
ensure_zero((uint8_t*)&data[0], size_);
}
@ -312,16 +304,15 @@ 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) {
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_);
}
@ -339,16 +330,15 @@ 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) {
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_);
}

View file

@ -7,10 +7,12 @@
class test : public benchmark::test_case
{
std::string expr_;
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_);
@ -24,14 +26,14 @@ public:
}
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_);
}
return true;
}
};
int main(int argc, char** argv)
{
mapnik::parameters params;

View file

@ -6,7 +6,8 @@ class test : public benchmark::test_case
{
public:
test(mapnik::parameters const& params)
: test_case(params) {}
: test_case(params)
{}
bool validate() const
{
std::size_t count = 0;
@ -22,7 +23,8 @@ public:
font_cache,
mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache());
if (f) ++count;
if (f)
++count;
}
return count == expected_count;
}
@ -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";
}
}
@ -58,7 +62,8 @@ int main(int argc, char** argv)
mapnik::parameters params;
benchmark::handle_args(argc, argv, params);
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;
}
@ -66,4 +71,3 @@ int main(int argc, char** argv)
test test_runner(params);
return run(test_runner, (boost::format("font_engine: creating %ld faces") % (face_count)).str());
}

View file

@ -7,11 +7,9 @@ class test : public benchmark::test_case
{
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;

View file

@ -1,15 +1,13 @@
#include "bench_framework.hpp"
#include "../plugins/input/csv/csv_getline.hpp"
class test : public benchmark::test_case
{
public:
std::string line_data_;
test(mapnik::parameters const& params)
: test_case(params),
line_data_("this is one line\nand this is a second line\nand a third line")
: 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)
@ -32,7 +30,8 @@ public:
}
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;
}
@ -50,14 +49,13 @@ public:
}
};
class test2 : public benchmark::test_case
{
public:
std::string line_data_;
test2(mapnik::parameters const& params)
: test_case(params),
line_data_("this is one line\nand this is a second line\nand a third line")
: 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)
@ -81,7 +79,8 @@ public:
}
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;
}
@ -115,8 +114,7 @@ int main(int argc, char** argv)
test2 test_runner2(params);
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,11 +4,11 @@
class test : public benchmark::test_case
{
std::vector<std::string> images_;
public:
test(mapnik::parameters const& params)
: test_case(params),
images_{
"./test/data/images/dummy.jpg",
: test_case(params)
, images_{"./test/data/images/dummy.jpg",
"./test/data/images/dummy.jpeg",
"./test/data/images/dummy.png",
"./test/data/images/dummy.tif",
@ -19,16 +19,14 @@ public:
"./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/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);

View file

@ -16,12 +16,10 @@ class test : public benchmark::test_case
{
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");

View file

@ -9,23 +9,25 @@ class test_static : public benchmark::test_case
{
double step_;
std::uint8_t start_;
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:
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(v.begin(), v.size())
{}
template<typename Itr>
fake_path(Itr itr, size_t sz) {
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,20 +53,16 @@ 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:
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;
@ -74,7 +75,8 @@ public:
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,7 +90,6 @@ public:
}
};
int main(int argc, char** argv)
{
mapnik::parameters params;

View file

@ -4,18 +4,18 @@
class test : public benchmark::test_case
{
mapnik::image_rgba8 im_;
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");
}

View file

@ -4,9 +4,11 @@
class test : public benchmark::test_case
{
std::shared_ptr<mapnik::image_rgba8> im_;
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"));
if (!reader.get())
@ -26,7 +28,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)
{
out.clear();
out = mapnik::save_to_string(*im_, "png8:m=h:z=1");
}

View file

@ -39,7 +39,8 @@ 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);
@ -70,15 +71,15 @@ class test1 : public benchmark::test_case
std::string wkt_in_;
mapnik::box2d<double> extent_;
std::string expected_;
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)
@ -135,7 +131,8 @@ public:
{
if (cmd == mapnik::SEG_MOVETO)
{
x0 = x; y0 = y;
x0 = x;
y0 = y;
}
else if (cmd == mapnik::SEG_CLOSE)
{
@ -184,23 +181,22 @@ 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());
unsigned cmd;
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") {}
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;
@ -308,12 +303,15 @@ public:
mapnik::geometry::polygon_vertex_adapter<double> va(_geom);
unsigned cmd;
double x, y;
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) {
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;
}
}
}
@ -516,10 +514,13 @@ int main(int argc, char** argv)
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");

View file

@ -8,13 +8,12 @@ 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)
test(mapnik::parameters const& params, std::string const& xml, mapnik::box2d<double> const& extent)
: test_case(params)
, xml_(xml)
, extent_(extent)
{}
bool validate() const
{
@ -42,7 +41,6 @@ public:
}
};
int main(int argc, char** argv)
{
mapnik::parameters params;

View file

@ -10,6 +10,7 @@ class test : public benchmark::test_case
mapnik::box2d<double> from_;
mapnik::box2d<double> to_;
bool defer_proj_init_;
public:
test(mapnik::parameters const& params,
std::string const& src,
@ -17,24 +18,23 @@ public:
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::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
{
@ -48,7 +48,8 @@ public:
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");
if (!tr.forward(box))
throw std::runtime_error("could not transform coords");
}
}
}
@ -64,7 +65,8 @@ int main(int argc, char** argv)
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)

View file

@ -8,12 +8,10 @@ class test : public benchmark::test_case
{
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
{

View file

@ -15,15 +15,16 @@ class test : public benchmark::test_case
mapnik::value_integer height_;
double scale_factor_;
std::string preview_;
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,21 +44,24 @@ 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()) {
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_);
ren.apply();
if (!preview_.empty()) {
if (!preview_.empty())
{
std::clog << "preview available at " << preview_ << "\n";
mapnik::save_to_file(im, preview_);
}
@ -65,14 +69,18 @@ public:
}
bool operator()() const
{
if (!preview_.empty()) {
if (!preview_.empty())
{
return false;
}
mapnik::Map m(width_, height_);
mapnik::load_map(m, xml_);
if (extent_.valid()) {
if (extent_.valid())
{
m.zoom_to_box(extent_);
} else {
}
else
{
m.zoom_all();
}
for (unsigned i = 0; i < iterations_; ++i)
@ -85,7 +93,6 @@ public:
}
};
int main(int argc, char** argv)
{
int return_value = 0;
@ -105,8 +112,7 @@ int main(int argc, char** argv)
test test_runner(params);
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,7 +12,8 @@
#include <mapnik/datasource_cache.hpp>
#include <stdexcept>
template <typename Renderer> void process_layers(Renderer & ren,
template<typename Renderer>
void process_layers(Renderer& ren,
mapnik::request const& m_req,
mapnik::projection const& map_proj,
std::vector<mapnik::layer> const& layers,
@ -50,17 +51,18 @@ class test : public benchmark::test_case
double scale_factor_;
std::string preview_;
mutable mapnik::image_rgba8 im_;
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)
@ -98,7 +100,8 @@ public:
std::vector<mapnik::layer> const& layers = m_->layers();
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_);
}
@ -107,7 +110,8 @@ public:
bool operator()() const
{
if (!preview_.empty()) {
if (!preview_.empty())
{
return false;
}
for (unsigned i = 0; i < iterations_; ++i)
@ -133,16 +137,17 @@ 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;
@ -162,8 +167,7 @@ int main(int argc, char** argv)
test test_runner(params);
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,21 +4,25 @@
class test : public benchmark::test_case
{
std::string value_;
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;
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);

View file

@ -4,23 +4,30 @@
class test : public benchmark::test_case
{
std::string value_;
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);

View file

@ -4,23 +4,30 @@
class test : public benchmark::test_case
{
std::string value_;
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);

View file

@ -4,10 +4,12 @@
class test : public benchmark::test_case
{
double value_;
public:
test(mapnik::parameters const& params)
: test_case(params),
value_(-0.1234) {}
: test_case(params)
, value_(-0.1234)
{}
bool validate() const
{
std::string 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)
{
out.clear();
mapnik::util::to_string(out, value_);
}

View file

@ -4,10 +4,12 @@
class test : public benchmark::test_case
{
double value_;
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();

View file

@ -13,26 +13,28 @@ using mapnik::util::from_u8string;
class test : public benchmark::test_case
{
std::string utf8_;
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) {
for (std::size_t i = 0; i < iterations_; ++i)
{
utf32 = utf32conv.from_bytes(utf8_);
}
return true;
@ -44,24 +46,26 @@ public:
class test2 : public benchmark::test_case
{
std::string utf8_;
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) {
for (std::size_t i = 0; i < iterations_; ++i)
{
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
}
return true;
@ -71,27 +75,29 @@ public:
class test3 : public benchmark::test_case
{
std::string utf8_;
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;
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) {
for (std::size_t i = 0; i < iterations_; ++i)
{
utf32 = tr_.transcode(utf8_.data(), utf8_.size());
}
return true;

View file

@ -4,14 +4,10 @@ class test : public benchmark::test_case
{
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")