-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmark.cpp
More file actions
77 lines (65 loc) · 1.69 KB
/
Benchmark.cpp
File metadata and controls
77 lines (65 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <benchmark/benchmark.h>
#include "SkipList.h"
#include <ranges>
#include <unordered_set>
#include <filesystem>
#include <fstream>
class sfc64
{
public:
using result_type = uint64_t;
static constexpr uint64_t (min)() { return 0; }
static constexpr uint64_t (max)() { return UINT64_C(-1); }
sfc64() : sfc64(std::random_device{}())
{
}
explicit sfc64(uint64_t seed) : m_a(seed), m_b(seed), m_c(seed), m_counter(1)
{
for (int i = 0; i < 12; ++i)
{
operator()();
}
}
uint64_t operator()() noexcept
{
auto const tmp = m_a + m_b + m_counter++;
m_a = m_b ^ (m_b >> right_shift);
m_b = m_c + (m_c << left_shift);
m_c = rotl(m_c, rotation) + tmp;
return tmp;
}
private:
template <typename T>
T rotl(T const x, int k) { return (x << k) | (x >> (8 * sizeof(T) - k)); }
static constexpr int rotation = 24;
static constexpr int right_shift = 11;
static constexpr int left_shift = 3;
uint64_t m_a;
uint64_t m_b;
uint64_t m_c;
uint64_t m_counter;
};
int64_t RandomNumber()
{
static auto gen = sfc64{};
return gen();
}
namespace Basic
{
template <class Container>
static void BM_ContainerFindRandom10XInX(benchmark::State& state)
{
for (auto _ : state)
{
Container cont;
for (auto i : std::ranges::iota_view{0, state.range(0)})
cont.insert(RandomNumber());
for (auto i : std::ranges::iota_view{0, 10*state.range(0)})
const auto p = cont.find(RandomNumber());
}
}
BENCHMARK_TEMPLATE(BM_ContainerFindRandom10XInX, std::set<int64_t>)->Range(0,32<<10);
BENCHMARK_TEMPLATE(BM_ContainerFindRandom10XInX, std::unordered_set<int64_t>)->Range(0,32<<10);
BENCHMARK_TEMPLATE(BM_ContainerFindRandom10XInX, skip_list<int64_t>)->Range(0,32<<10);
}