From f9ad079d399068955747e2de435a2c7bec958acc Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 5 May 2014 10:08:25 -0700 Subject: [PATCH] benchmark: break out string to int/bool/double conversions --- benchmark/test_to_bool.cpp | 29 +---------------------------- benchmark/test_to_double.cpp | 31 +++++++++++++++++++++++++++++++ benchmark/test_to_int.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 benchmark/test_to_double.cpp create mode 100644 benchmark/test_to_int.cpp diff --git a/benchmark/test_to_bool.cpp b/benchmark/test_to_bool.cpp index 62b9d13a0..92f073156 100644 --- a/benchmark/test_to_bool.cpp +++ b/benchmark/test_to_bool.cpp @@ -26,31 +26,4 @@ public: } }; -class test2 : public benchmark::test_case -{ - std::string value_; -public: - test2(mapnik::parameters const& params) - : test_case(params), - value_("1.23456789") {} - bool validate() const - { - double result = 0; - mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result); - if (result != 1.23456789) return false; - result = 0; - mapnik::util::string2double(value_,result); - return (result == 1.23456789); - } - void operator()() const - { - for (std::size_t i=0;ibool") -BENCHMARK(test2,"string->double") +BENCHMARK(test,"string->bool") diff --git a/benchmark/test_to_double.cpp b/benchmark/test_to_double.cpp new file mode 100644 index 000000000..1605dcd06 --- /dev/null +++ b/benchmark/test_to_double.cpp @@ -0,0 +1,31 @@ +#include "bench_framework.hpp" +#include + +class test : public benchmark::test_case +{ + std::string value_; +public: + test(mapnik::parameters const& params) + : 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; + result = 0; + if (!mapnik::util::string2double(value_,result)) return false; + if (result != 1.23456789) return false; + return true; + } + void operator()() const + { + for (std::size_t i=0;idouble") diff --git a/benchmark/test_to_int.cpp b/benchmark/test_to_int.cpp new file mode 100644 index 000000000..195d0336b --- /dev/null +++ b/benchmark/test_to_int.cpp @@ -0,0 +1,31 @@ +#include "bench_framework.hpp" +#include + +class test : public benchmark::test_case +{ + std::string value_; +public: + test(mapnik::parameters const& params) + : 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; + result = 0; + if (!mapnik::util::string2int(value_,result)) return false; + if (result != 123456789) return false; + return true; + } + void operator()() const + { + for (std::size_t i=0;iint")