| 88 | }; |
| 89 | |
| 90 | class ShakerSort : public CppBenchmark::Benchmark, public SortFixture |
| 91 | { |
| 92 | public: |
| 93 | using Benchmark::Benchmark; |
| 94 | |
| 95 | protected: |
| 96 | void Run(CppBenchmark::Context& context) override |
| 97 | { |
| 98 | // Generate items to sort |
| 99 | std::generate(items.begin(), items.end(), rand); |
| 100 | |
| 101 | // Start values of left and right bound |
| 102 | size_t left = 1; |
| 103 | size_t right = items.size(); |
| 104 | |
| 105 | // While left and right bound not met... |
| 106 | while (left < right) |
| 107 | { |
| 108 | // Bubble down minimal item to the left bound |
| 109 | for (size_t i = right; i > left; --i) |
| 110 | { |
| 111 | if (items[i - 1] < items[i - 1 - 1]) |
| 112 | std::swap(items[i - 1], items[i - 1 - 1]); |
| 113 | } |
| 114 | |
| 115 | // Increment left bound |
| 116 | ++left; |
| 117 | |
| 118 | // Bubble up maximal item to the right bound |
| 119 | for (size_t i = left; i < right; ++i) |
| 120 | { |
| 121 | if (items[i + 1 - 1] < items[i - 1]) |
| 122 | std::swap(items[i + 1 - 1], items[i - 1]); |
| 123 | } |
| 124 | |
| 125 | // Decrement right bound |
| 126 | --right; |
| 127 | } |
| 128 | context.metrics().AddItems(items.size()); |
| 129 | } |
| 130 | }; |
| 131 | |
| 132 | class GnomeSort : public CppBenchmark::Benchmark, public SortFixture |
| 133 | { |
nothing calls this directly
no outgoing calls
no test coverage detected