add std::string and std::valarray to array allocation benchmark
This commit is contained in:
parent
fb0dca7b54
commit
79a82cd8ff
1 changed files with 84 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <array>
|
||||
#include <valarray>
|
||||
|
||||
// http://stackoverflow.com/questions/17347254/why-is-allocation-and-deallocation-of-stdvector-slower-than-dynamic-array-on-m
|
||||
|
||||
|
@ -189,6 +190,77 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class test5 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test5(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::string data(array_.begin(),array_.end());
|
||||
ensure_zero((uint8_t *)&data[0],size_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class test5b : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<char> array_;
|
||||
test5b(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::string data(&array_[0]);
|
||||
ensure_zero((uint8_t *)&data[0],size_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// C++14 dynarray<T>
|
||||
// http://isocpp.org/blog/2013/04/trip-report-iso-c-spring-2013-meeting
|
||||
// http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130909/088700.html
|
||||
// http://stackoverflow.com/questions/17303902/any-alternative-to-stddynarray-presently-available
|
||||
|
||||
class test6 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test6(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::valarray<uint8_t> data(size_,0);
|
||||
ensure_zero(&data[0],size_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
|
@ -222,5 +294,17 @@ int main(int argc, char** argv)
|
|||
test3c test_runner(params);
|
||||
run(test_runner,"vector/assign");
|
||||
}
|
||||
{
|
||||
test5 test_runner(params);
|
||||
run(test_runner,"std::string range");
|
||||
}
|
||||
{
|
||||
test5 test_runner(params);
|
||||
run(test_runner,"std::string &[0]");
|
||||
}
|
||||
{
|
||||
test5 test_runner(params);
|
||||
run(test_runner,"valarray");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue