| 421 | }; |
| 422 | |
| 423 | static 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 | |
| 443 | BENCHMARK(sorting)->Args({3, false})->Args({3, true}); |
| 444 | BENCHMARK(sorting)->Args({4, false})->Args({4, true}); |