#include "bench_framework.hpp" #include #include #include #include // http://stackoverflow.com/questions/17347254/why-is-allocation-and-deallocation-of-stdvector-slower-than-dynamic-array-on-m #define FULL_ZERO_CHECK inline void ensure_zero(uint8_t * data, uint32_t size) { #ifdef FULL_ZERO_CHECK for (std::size_t i=0;i array_; test1(mapnik::parameters const& params) : test_case(params), size_(*params.get("size",256*256)), array_(size_,0) { } bool validate() const { return true; } void operator()() const { for (std::size_t i=0;i array_; test1b(mapnik::parameters const& params) : test_case(params), size_(*params.get("size",256*256)), array_(size_,0) { } bool validate() const { return true; } void operator()() const { for (std::size_t i=0;i array_; test2(mapnik::parameters const& params) : test_case(params), size_(*params.get("size",256*256)), array_(size_,0) { } bool validate() const { return true; } void operator()() const { for (std::size_t i=0;i(::operator new(sizeof(uint8_t)*size_)); memcpy(data, &array_[0], size_); ensure_zero(data,size_); ::operator delete(data),data=0; } } }; class test3 : public benchmark::test_case { public: uint32_t size_; std::vector array_; test3(mapnik::parameters const& params) : test_case(params), size_(*params.get("size",256*256)), array_(size_,0) { } bool validate() const { return true; } void operator()() const { for (std::size_t i=0;i data(size_); ensure_zero(&data[0],data.size()); } } }; class test3b : public benchmark::test_case { public: uint32_t size_; std::vector array_; test3b(mapnik::parameters const& params) : test_case(params), size_(*params.get("size",256*256)), array_(size_,0) { } bool validate() const { return true; } void operator()() const { for (std::size_t i=0;i data(0); data.resize(size_,0); ensure_zero(&data[0],data.size()); } } }; class test3c : public benchmark::test_case { public: uint32_t size_; std::vector array_; test3c(mapnik::parameters const& params) : test_case(params), size_(*params.get("size",256*256)), array_(size_,0) { } bool validate() const { return true; } void operator()() const { for (std::size_t i=0;i data(0); data.assign(size_,0); ensure_zero(&data[0],data.size()); } } }; class test4 : public benchmark::test_case { public: uint32_t size_; std::vector array_; test4(mapnik::parameters const& params) : test_case(params), size_(*params.get("size",256*256)), array_(size_,0) { } bool validate() const { return true; } void operator()() const { for (std::size_t i=0;i