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

Method Run

examples/sort.cpp:67–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65
66protected:
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
90class ShakerSort : public CppBenchmark::Benchmark, public SortFixture

Callers

nothing calls this directly

Calls 2

AddItemsMethod · 0.80
swapFunction · 0.50

Tested by

no test coverage detected