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

Class InsertSort

examples/sort.cpp:176–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174};
175
176class InsertSort : public CppBenchmark::Benchmark, public SortFixture
177{
178public:
179 using Benchmark::Benchmark;
180
181protected:
182 void Run(CppBenchmark::Context& context) override
183 {
184 // Generate items to sort
185 std::generate(items.begin(), items.end(), rand);
186
187 // Sort items
188 for (size_t i = 1; i < items.size(); ++i)
189 {
190 // Take the next item
191 for (size_t j = i + 1; j > 1; --j)
192 {
193 // Check the current item with the previous one
194 if (items[j - 1] < items[j - 1 - 1])
195 std::swap(items[j - 1], items[j - 1 - 1]);
196 }
197 }
198 context.metrics().AddItems(items.size());
199 }
200};
201
202class ShellSort : public CppBenchmark::Benchmark, public SortFixture
203{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected