benchmark: break out string to int/bool/double conversions

This commit is contained in:
Dane Springmeyer 2014-05-05 10:08:25 -07:00
parent 7158df8b08
commit f9ad079d39
3 changed files with 63 additions and 28 deletions

View file

@ -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;i<iterations_;++i) {
double result = 0;
mapnik::util::string2double(value_,result);
//mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
}
}
};
//BENCHMARK(test,"string->bool")
BENCHMARK(test2,"string->double")
BENCHMARK(test,"string->bool")

View file

@ -0,0 +1,31 @@
#include "bench_framework.hpp"
#include <mapnik/util/conversions.hpp>
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;i<iterations_;++i) {
double result = 0;
mapnik::util::string2double(value_,result);
mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
}
}
};
BENCHMARK(test,"string->double")

31
benchmark/test_to_int.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "bench_framework.hpp"
#include <mapnik/util/conversions.hpp>
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;i<iterations_;++i) {
mapnik::value_integer result = 0;
mapnik::util::string2int(value_,result);
mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result);
}
}
};
BENCHMARK(test,"string->int")