#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) { mapnik::parameters params; benchmark::handle_args(argc,argv,params); int return_value = 0; { test_static test_runner(params); return_value = return_value | run(test_runner,"static_cast"); } { test_numeric test_runner(params); return_value = return_value | run(test_runner,"numeric_cast"); } return return_value; }