| 65 | |
| 66 | protected: |
| 67 | void Run(CppBenchmark::Context& context) override |
| 68 | { |
| 69 | // Generate items to sort |
| 70 | std::generate(items.begin(), items.end(), rand); |
| 71 | |
| 72 | // Iterate through all items to get the current bound |
| 73 | for (size_t i = 0; i < items.size(); ++i) |
| 74 | { |
| 75 | // Calculate the current bound |
| 76 | size_t bound = items.size() - i; |
| 77 | |
| 78 | // Starting from the current items and for all next items before the bound... |
| 79 | for (size_t j = 1; j < bound; ++j) |
| 80 | { |
| 81 | // Swap items to bubble up minimal one to the end |
| 82 | if (items[j] < items[j - 1]) |
| 83 | std::swap(items[j], items[j - 1]); |
| 84 | } |
| 85 | } |
| 86 | context.metrics().AddItems(items.size()); |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | class ShakerSort : public CppBenchmark::Benchmark, public SortFixture |