| 28 | }; |
| 29 | |
| 30 | class SelectionSort : public CppBenchmark::Benchmark, public SortFixture |
| 31 | { |
| 32 | public: |
| 33 | using Benchmark::Benchmark; |
| 34 | |
| 35 | protected: |
| 36 | void Run(CppBenchmark::Context& context) override |
| 37 | { |
| 38 | // Generate items to sort |
| 39 | std::generate(items.begin(), items.end(), rand); |
| 40 | |
| 41 | // Sort items |
| 42 | for (size_t i = 0; i < items.size(); ++i) |
| 43 | { |
| 44 | // Set the current item as minimal |
| 45 | size_t min = i; |
| 46 | |
| 47 | // Found in rest items another minimal |
| 48 | for (size_t j = i + 1; j < items.size(); ++j) |
| 49 | { |
| 50 | if (items[j] < items[min]) |
| 51 | min = j; |
| 52 | } |
| 53 | |
| 54 | // Swap the current item with minimal |
| 55 | std::swap(items[i], items[min]); |
| 56 | } |
| 57 | context.metrics().AddItems(items.size()); |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | class BubbleSort : public CppBenchmark::Benchmark, public SortFixture |
| 62 | { |
nothing calls this directly
no outgoing calls
no test coverage detected