Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / benchmarks / random.bench.cpp
blobfe2eb6672ae79689df37184af9c35580371ee585
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 //===----------------------------------------------------------------------===//
8 #include <algorithm>
9 #include <array>
10 #include <cstddef>
11 #include <functional>
12 #include <random>
14 #include "benchmark/benchmark.h"
16 constexpr std::size_t MAX_BUFFER_LEN = 256;
17 constexpr std::size_t MAX_SEED_LEN = 16;
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;
23 std::random_device rd;
24 std::generate(std::begin(seeds), std::begin(seeds) + state.range(0), [&]() { return rd(); });
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));
31 BENCHMARK(BM_SeedSeq_Generate)->Ranges({{1, MAX_SEED_LEN}, {1, MAX_BUFFER_LEN}});
33 BENCHMARK_MAIN();