Laramie Leavitt | 9c35c4d | 2022-05-24 10:27:37 +0200 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | // See https://llvm.org/LICENSE.txt for license information. |
| 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
| 8 | #include <algorithm> |
| 9 | #include <array> |
| 10 | #include <cstddef> |
| 11 | #include <functional> |
| 12 | #include <random> |
| 13 | |
| 14 | #include "benchmark/benchmark.h" |
| 15 | |
| 16 | constexpr std::size_t MAX_BUFFER_LEN = 256; |
| 17 | constexpr std::size_t MAX_SEED_LEN = 16; |
| 18 | |
| 19 | static void BM_SeedSeq_Generate(benchmark::State& state) { |
| 20 | std::array<std::uint32_t, MAX_BUFFER_LEN> buffer; |
| 21 | std::array<std::uint32_t, MAX_SEED_LEN> seeds; |
| 22 | { |
| 23 | std::random_device rd; |
| 24 | std::generate(std::begin(seeds), std::begin(seeds) + state.range(0), [&]() { return rd(); }); |
| 25 | } |
| 26 | std::seed_seq seed(std::begin(seeds), std::begin(seeds) + state.range(0)); |
| 27 | for (auto _ : state) { |
| 28 | seed.generate(std::begin(buffer), std::begin(buffer) + state.range(1)); |
| 29 | } |
| 30 | } |
| 31 | BENCHMARK(BM_SeedSeq_Generate)->Ranges({{1, MAX_SEED_LEN}, {1, MAX_BUFFER_LEN}}); |
| 32 | |
| 33 | BENCHMARK_MAIN(); |