blob: e437849321da0607e34ae92cae68130247fa7914 [file] [log] [blame]
Laramie Leavitt9c35c4d2022-05-24 10:27:37 +02001//===----------------------------------------------------------------------===//
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(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}
31BENCHMARK(BM_SeedSeq_Generate)->Ranges({{1, MAX_SEED_LEN}, {1, MAX_BUFFER_LEN}});
32
33BENCHMARK_MAIN();