Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
random.cpp
Go to the documentation of this file.
1// Copyright (c) The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <bench/bench.h>
6#include <random.h>
7
8#include <algorithm>
9#include <cstdint>
10#include <iterator>
11#include <numeric>
12
13namespace {
14
15template<typename RNG>
16void BenchRandom_rand64(benchmark::Bench& bench, RNG&& rng) noexcept
17{
18 bench.batch(1).unit("number").run([&] {
19 rng.rand64();
20 });
21}
22
23template<typename RNG>
24void BenchRandom_rand32(benchmark::Bench& bench, RNG&& rng) noexcept
25{
26 bench.batch(1).unit("number").run([&] {
27 rng.rand32();
28 });
29}
30
31template<typename RNG>
33{
34 bench.batch(1).unit("number").run([&] {
35 rng.randbool();
36 });
37}
38
39template<typename RNG>
41{
42 bench.batch(64).unit("number").run([&] {
43 for (int i = 1; i <= 64; ++i) {
44 rng.randbits(i);
45 }
46 });
47}
48
49template<int RANGE, typename RNG>
51{
52 bench.batch(RANGE).unit("number").run([&] {
53 for (int i = 1; i <= RANGE; ++i) {
54 rng.randrange(i);
55 }
56 });
57}
58
59template<int RANGE, typename RNG>
61{
62 uint64_t data[RANGE];
63 std::iota(std::begin(data), std::end(data), uint64_t(0));
64 bench.batch(RANGE).unit("number").run([&] {
65 std::shuffle(std::begin(data), std::end(data), rng);
66 });
67}
68
77
86
87} // namespace
88
97
#define BENCHMARK(n)
Definition bench.h:68
Fast randomness source.
Definition random.h:386
xoroshiro128++ PRNG.
Definition random.h:425
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:627
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73