benchmark: break out string to int/bool/double conversions
This commit is contained in:
parent
7158df8b08
commit
f9ad079d39
3 changed files with 63 additions and 28 deletions
|
@ -26,31 +26,4 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test2 : public benchmark::test_case
|
BENCHMARK(test,"string->bool")
|
||||||
{
|
|
||||||
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")
|
|
||||||
|
|
31
benchmark/test_to_double.cpp
Normal file
31
benchmark/test_to_double.cpp
Normal 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
31
benchmark/test_to_int.cpp
Normal 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")
|
Loading…
Add table
Reference in a new issue