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