diff --git a/bench/bench_alloc_expand_fwd.cpp b/bench/bench_alloc_expand_fwd.cpp index 8b6f1a1..2293a0b 100644 --- a/bench/bench_alloc_expand_fwd.cpp +++ b/bench/bench_alloc_expand_fwd.cpp @@ -24,81 +24,41 @@ #include //std::cout, std::endl #include //std::strcmp #include +#include using boost::timer::cpu_timer; using boost::timer::cpu_times; using boost::timer::nanosecond_type; namespace bc = boost::container; -typedef std::allocator StdAllocator; -typedef bc::allocator AllocatorPlusV2Mask; -typedef bc::allocator AllocatorPlusV2; -typedef bc::allocator AllocatorPlusV1; - -template struct get_allocator_name; - -template<> struct get_allocator_name -{ static const char *get() { return "StdAllocator"; } }; - -template<> struct get_allocator_name -{ static const char *get() { return "AllocatorPlusV2Mask"; } }; - -template<> struct get_allocator_name -{ static const char *get() { return "AllocatorPlusV2"; } }; - -template<> struct get_allocator_name -{ static const char *get() { return "AllocatorPlusV1"; } }; - #if defined(BOOST_CONTAINER_VECTOR_ALLOC_STATS) -// -// stats_traits; -// -template class Vector> -struct stats_traits; +template +static void reset_alloc_stats(std::vector &) + {} -template<> -struct stats_traits -{ - template - static void reset_alloc_stats(std::vector &) - {} +template +static std::size_t get_num_alloc(std::vector &) + { return 0; } - template - static std::size_t get_num_alloc(std::vector &) - { return 0; } +template +static std::size_t get_num_expand(std::vector &) + { return 0; } - template - static std::size_t get_num_expand(std::vector &) - { return 0; } -}; +template +static void reset_alloc_stats(bc::vector &v) + { v.reset_alloc_stats(); } -template<> -struct stats_traits -{ - template - static void reset_alloc_stats(bc::vector &v) - { v.reset_alloc_stats(); } +template +static std::size_t get_num_alloc(bc::vector &v) + { return v.num_alloc; } - template - static std::size_t get_num_alloc(bc::vector &v) - { return v.num_alloc; } - - template - static std::size_t get_num_expand(bc::vector &v) - { return v.num_expand_fwd; } -}; +template +static std::size_t get_num_expand(bc::vector &v) + { return v.num_expand_fwd; } #endif //BOOST_CONTAINER_VECTOR_ALLOC_STATS -template class Vector> struct get_container_name; - -template<> struct get_container_name -{ static const char *get() { return "StdVector"; } }; - -template<> struct get_container_name -{ static const char *get() { return "BoostContainerVector"; } }; - class MyInt { int int_; @@ -124,24 +84,19 @@ class MyInt } }; -template class Vector> -void vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output) +template +void vector_test_template(unsigned int num_iterations, unsigned int num_elements) { - typedef typename Allocator::template rebind::other IntAllocator; unsigned int numalloc = 0, numexpand = 0; - #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS - typedef stats_traits stats_traits_t; - #endif - cpu_timer timer; timer.resume(); unsigned int capacity = 0; for(unsigned int r = 0; r != num_iterations; ++r){ - Vector v; + Container v; #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS - stats_traits_t::reset_alloc_stats(v); + reset_alloc_stats(v); #endif //v.reserve(num_elements); //MyInt a[3]; @@ -183,8 +138,8 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements } #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS - numalloc += stats_traits_t::get_num_alloc(v); - numexpand += stats_traits_t::get_num_expand(v); + numalloc += get_num_alloc(v); + numexpand += get_num_expand(v); #endif capacity = static_cast(v.capacity()); } @@ -192,37 +147,17 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements timer.stop(); nanosecond_type nseconds = timer.elapsed().wall; - if(csv_output){ - std::cout << get_allocator_name::get() - << ";" - << num_iterations - << ";" - << num_elements - << ";" - << capacity - << ";" - << float(nseconds)/(num_iterations*num_elements) - << ";" + std::cout << std::endl + << "Allocator: " << typeid(typename Container::allocator_type).name() + << std::endl + << " push_back ns: " + << float(nseconds)/(num_iterations*num_elements) + << std::endl + << " capacity - alloc calls (new/expand): " + << (unsigned int)capacity << " - " << (float(numalloc) + float(numexpand))/num_iterations - << ";" - << float(numalloc)/num_iterations - << ";" - << float(numexpand)/num_iterations - << std::endl; - } - else{ - std::cout << std::endl - << "Allocator: " << get_allocator_name::get() - << std::endl - << " push_back ns: " - << float(nseconds)/(num_iterations*num_elements) - << std::endl - << " capacity - alloc calls (new/expand): " - << (unsigned int)capacity << " - " - << (float(numalloc) + float(numexpand))/num_iterations - << "(" << float(numalloc)/num_iterations << "/" << float(numexpand)/num_iterations << ")" - << std::endl << std::endl; - } + << "(" << float(numalloc)/num_iterations << "/" << float(numexpand)/num_iterations << ")" + << std::endl << std::endl; bc::dlmalloc_trim(0); } @@ -233,7 +168,7 @@ void print_header() << "New allocations" << ";" << "Fwd expansions" << std::endl; } -int main(int argc, const char *argv[]) +int main() { #define SINGLE_TEST #ifndef SINGLE_TEST @@ -252,34 +187,12 @@ int main(int argc, const char *argv[]) std::size_t numele [] = { 10000 }; #endif - bool csv_output = argc == 2 && (strcmp(argv[1], "--csv-output") == 0); - - if(csv_output){ - print_header(); - for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ - vector_test_template(numit[i], numele[i], csv_output); - } - for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ - vector_test_template(numit[i], numele[i], csv_output); - } - for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ - vector_test_template(numit[i], numele[i], csv_output); - } - for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ - vector_test_template(numit[i], numele[i], csv_output); - } - } - else{ - for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ - std::cout << "\n ----------------------------------- \n" - << " Iterations/Elements: " << numit[i] << "/" << numele[i] - << "\n ----------------------------------- \n"; - vector_test_template(numit[i], numele[i], csv_output); - vector_test_template(numit[i], numele[i], csv_output); - vector_test_template(numit[i], numele[i], csv_output); - vector_test_template(numit[i], numele[i], csv_output); - vector_test_template(numit[i], numele[i], csv_output); - } + print_header(); + for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ + vector_test_template< bc::vector > >(numit[i], numele[i]); + vector_test_template< bc::vector > >(numit[i], numele[i]); + vector_test_template > >(numit[i], numele[i]); + vector_test_template > >(numit[i], numele[i]); } return 0; }