/******************************************************************************* * tests/container/d_ary_heap_speedtest.cpp * * Part of tlx - http://panthema.net/tlx * * Copyright (C) 2008-2019 Timo Bingmann * * All rights reserved. Published under the Boost Software License, Version 1.0 ******************************************************************************/ #include #include #include #include #include #include #include #include #include #include // *** Settings //! starting number of items to insert const size_t min_items = 125; //! maximum number of items to insert const size_t max_items = 1024000 * 128; // ----------------------------------------------------------------------------- //! Fill a generic heap type with pushes template class Test_Heap_Fill { public: Test_Heap_Fill(size_t) { } static const char * op() { return "heap_fill"; } void run(size_t items) { HeapType heap; for (size_t i = 0; i < items; i++) heap.push(items - i); die_unless(heap.size() == items); } }; //! Test a generic heap type by filling and emptying it template class Test_Heap_FillPopAll { public: Test_Heap_FillPopAll(size_t) { } static const char * op() { return "heap_fill_popall"; } void run(size_t items) { HeapType heap; for (size_t i = 0; i < items; i++) heap.push(items - i); die_unless(heap.size() == items); for (size_t i = 0; i < items; i++) heap.pop(); die_unless(heap.empty()); } }; //! Test a generic heap type by filling and cycling it. template class Test_Heap_FillCycle { public: HeapType heap_; Test_Heap_FillCycle(size_t items) { // fill up heap for (size_t i = 0; i < items; i++) heap_.push(items - i); die_unless(heap_.size() == items); } static const char * op() { return "heap_fill_cycle"; } void run(size_t items) { HeapType heap = heap_; // cycle heap once for (size_t i = 0; i < items; i++) { heap.pop(); heap.push(2 * items - i); } die_unless(heap.size() == items); } }; // ----------------------------------------------------------------------------- //! Construct different heap types for a generic test class template