MCPcopy Create free account
hub / github.com/chronoxor/CppBenchmark / SelectionSort

Class SelectionSort

examples/sort.cpp:30–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28};
29
30class SelectionSort : public CppBenchmark::Benchmark, public SortFixture
31{
32public:
33 using Benchmark::Benchmark;
34
35protected:
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
61class BubbleSort : public CppBenchmark::Benchmark, public SortFixture
62{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected