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
16constexpr std::size_t MAX_BUFFER_LEN = 256;
17constexpr std::size_t MAX_SEED_LEN = 16;
18
19static 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(first: std::begin(cont&: seeds), last: std::begin(cont&: seeds) + state.range(pos: 0), gen: [&]() { return rd(); });
25 }
26 std::seed_seq seed(std::begin(cont&: seeds), std::begin(cont&: seeds) + state.range(pos: 0));
27 for (auto _ : state) {
28 seed.generate(begin: std::begin(cont&: buffer), end: std::begin(cont&: buffer) + state.range(pos: 1));
29 }
30}
31BENCHMARK(BM_SeedSeq_Generate)->Ranges(ranges: {{1, MAX_SEED_LEN}, {1, MAX_BUFFER_LEN}});
32
33BENCHMARK_MAIN();
34

source code of libcxx/benchmarks/random.bench.cpp