Skip to content

Commit 1d6f63b

Browse files
committed
Update Tests for uniform_int_distribution
1 parent 9d570d5 commit 1d6f63b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 <cstdint>
12+
#include <random>
13+
14+
#include <benchmark/benchmark.h>
15+
16+
template <typename Eng, std::uint64_t Max>
17+
static void bm_uniform_int_distribution(benchmark::State& state) {
18+
Eng eng;
19+
std::uniform_int_distribution<std::uint64_t> dist(1ull, Max);
20+
for (auto _ : state) {
21+
benchmark::DoNotOptimize(dist(eng));
22+
}
23+
}
24+
25+
// n = 1
26+
// Best Case
27+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, 1ull << 20>);
28+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, 1ull << 20>);
29+
// Worst Case
30+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, (1ull << 19) + 1ull>);
31+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, (1ull << 19) + 1ull>);
32+
// Median Case
33+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, (1ull << 19) + (1ull << 18)>);
34+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, (1ull << 19) + (1ull << 18)>);
35+
36+
// n = 2, n0 = 2
37+
// Best Case
38+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, 1ull << 40>);
39+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, 1ull << 40>);
40+
// Worst Case
41+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, (1ull << 39) + 1ull>);
42+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, (1ull << 39) + 1ull>);
43+
// Median Case
44+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, (1ull << 39) + (1ull << 38)>);
45+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, (1ull << 39) + (1ull << 38)>);
46+
47+
// n = 2, n0 = 1
48+
// Best Case
49+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, 1ull << 41>);
50+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, 1ull << 41>);
51+
// Worst Case
52+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, (1ull << 40) + 1ull>);
53+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, (1ull << 40) + 1ull>);
54+
// Median Case
55+
BENCHMARK(bm_uniform_int_distribution<std::minstd_rand0, (1ull << 40) + (1ull << 39)>);
56+
BENCHMARK(bm_uniform_int_distribution<std::ranlux24_base, (1ull << 40) + (1ull << 39)>);
57+
58+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)