From fb0dca7b5419b5a8876f9440eb2dd6b3b8aac270 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 28 Jan 2014 19:47:23 -0800 Subject: [PATCH] array allocation test --- benchmark/run | 1 + benchmark/test_array_allocation.cpp | 226 ++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 benchmark/test_array_allocation.cpp diff --git a/benchmark/run b/benchmark/run index a909710ca..c4b0deb40 100755 --- a/benchmark/run +++ b/benchmark/run @@ -10,6 +10,7 @@ function run { ${BASE}/$1 --threads $2 --iterations $(expr $3 / $2); } +run test_array_allocation 20 100000 run test_png_encoding1 10 1000 run test_png_encoding2 10 50 run test_to_string1 10 100000 diff --git a/benchmark/test_array_allocation.cpp b/benchmark/test_array_allocation.cpp new file mode 100644 index 000000000..f21dd8648 --- /dev/null +++ b/benchmark/test_array_allocation.cpp @@ -0,0 +1,226 @@ +#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