Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / benchmarks / random.bench.cpp
blobe6af4c3e26eaf81bd966d9809add761b62356a52
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 #include <algorithm>
12 #include <array>
13 #include <cstddef>
14 #include <cstdint>
15 #include <functional>
16 #include <random>
18 #include "benchmark/benchmark.h"
20 constexpr std::size_t MAX_BUFFER_LEN = 256;
21 constexpr std::size_t MAX_SEED_LEN = 16;
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;
27 std::random_device rd;
28 std::generate(std::begin(seeds), std::begin(seeds) + state.range(0), [&]() { return rd(); });
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));
35 BENCHMARK(BM_SeedSeq_Generate)->Ranges({{1, MAX_SEED_LEN}, {1, MAX_BUFFER_LEN}});
37 BENCHMARK_MAIN();