#include "bench_framework.hpp" // boost #include static double STEP_NUM = 0.0000000001; static std::uint8_t START_NUM = 2; 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; } bool operator()() const { double value_ = 0.0; std::uint8_t x; for (std::size_t i=0;i(start_) * value_; if (c >= 256.0) c = 255.0; if (c < 0.0) c = 0.0; x = static_cast(c); value_ += step_; } return static_cast(x) < (static_cast(start_) * value_); } }; using boost::numeric::positive_overflow; using boost::numeric::negative_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; } bool operator()() const { double value_ = 0.0; std::uint8_t x; for (std::size_t i=0;i(start_ * value_); } catch(negative_overflow&) { x = std::numeric_limits::min(); } catch(positive_overflow&) { x = std::numeric_limits::max(); } value_ += step_; } return static_cast(x) < (static_cast(start_) * value_); } }; int main(int argc, char** argv) { return benchmark::sequencer(argc, argv) .run("static_cast") .run("numeric_cast") .done(); }