MCPcopy Create free account
hub / github.com/ashvardanian/less_slow.cpp / sorting

Function sorting

less_slow.cpp:423–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

421};
422
423static void sorting(bm::State &state) {
424
425 auto length = static_cast<std::size_t>(state.range(0));
426 auto include_preprocessing = static_cast<bool>(state.range(1));
427
428 aligned_array<std::uint32_t> array(length);
429 std::iota(array.begin(), array.end(), 1u);
430
431 for (auto _ : state) {
432
433 if (!include_preprocessing) state.PauseTiming();
434 // Reverse order is the most classical worst case, but not the only one.
435 std::reverse(array.begin(), array.end());
436 if (!include_preprocessing) state.ResumeTiming();
437 std::sort(array.begin(), array.end());
438 }
439
440 if (!std::is_sorted(array.begin(), array.end())) state.SkipWithError("Array is not sorted!");
441}
442
443BENCHMARK(sorting)->Args({3, false})->Args({3, true});
444BENCHMARK(sorting)->Args({4, false})->Args({4, true});

Callers

nothing calls this directly

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected