-
Notifications
You must be signed in to change notification settings - Fork 0
/
decay.cpp
141 lines (128 loc) · 3.83 KB
/
decay.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2020 The Division Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Author [email protected] && [email protected]
#include <benchmark/benchmark.h>
#include <iostream>
#include <llvm/ADT/DenseMap.h>
#include <llvm/ADT/DenseSet.h>
#include <llvm/ADT/simple_ilist.h>
#include <unordered_map>
#include "utils/symbol.h"
template <typename... T> void PrintVector(T &&...t)
{
(..., (std::cout << demangle(typeid(t).name()) << " size " << sizeof(typename T::value_type) << '\n'));
std::cout << '\n';
}
template <typename... T> void PrintContainer(T &&...t)
{
(..., (std::cout << demangle(typeid(typename T::value_type).name()) << " size " << sizeof(typename T::value_type) << '\n'));
std::cout << '\n';
}
template <typename... T> void PrintList(T &&...t)
{
(..., (std::cout << demangle(typeid(t).name()) << " size " << sizeof(t) << '\n'));
std::cout << '\n';
}
struct Hasher
{
size_t operator()(int key) const
{
return 1;
}
};
template <typename T> struct KeyInfo
{
static inline T getEmptyKey()
{
return ~0;
}
static inline T getTombstoneKey()
{
return ~0 - 1;
}
static unsigned getHashValue(const T &Val)
{
return 1;
}
static bool isEqual(const T &LHS, const T &RHS)
{
return LHS == RHS;
}
};
static void BM_unmap(benchmark::State &state)
{
std::unordered_map<int, int> unmap;
for (auto _ : state)
{
for (int i = 0; i < 10000; i++)
{
unmap[i] = i;
}
}
}
static void BM_decay_map(benchmark::State &state)
{
std::unordered_map<int, int, Hasher> decay_unmap;
for (auto _ : state)
{
for (int i = 0; i < 10000; i++)
{
decay_unmap[i] = i;
}
}
}
BENCHMARK(BM_unmap);
BENCHMARK(BM_decay_map);
static void BM_DenseMap(benchmark::State &state)
{
llvm::DenseMap<int, int> unmap;
for (auto _ : state)
{
for (int i = 0; i < 10000; i++)
{
unmap[i] = i;
}
}
}
static void BM_Decay_DenseMap(benchmark::State &state)
{
llvm::DenseMap<int, int, KeyInfo<int>> decay_unmap;
for (auto _ : state)
{
for (int i = 0; i < 10000; i++)
{
decay_unmap[i] = i;
}
}
}
BENCHMARK(BM_DenseMap);
BENCHMARK(BM_Decay_DenseMap);
struct LNode : public llvm::ilist_node<LNode, llvm::ilist_tag<LNode>>
{
char c;
LNode() {}
};
int main(int argc, char **argv)
{
PrintList(llvm::detail::DenseSetPair<uint8_t>{}, llvm::detail::DenseSetPair<uint16_t>{}, llvm::detail::DenseSetPair<uint32_t>{},
llvm::detail::DenseSetPair<uint64_t>{});
PrintList(llvm::detail::DenseMapPair<uint8_t, uint8_t>{}, llvm::detail::DenseMapPair<uint16_t, uint16_t>{},
llvm::detail::DenseMapPair<uint32_t, uint32_t>{}, llvm::detail::DenseMapPair<uint64_t, uint64_t>{});
PrintList(std::pair<uint8_t, uint8_t>{}, std::pair<uint16_t, uint16_t>{}, std::pair<uint32_t, uint32_t>{}, std::pair<uint64_t, uint64_t>{});
PrintContainer(llvm::DenseMap<uint8_t, uint8_t, KeyInfo<uint8_t>>{}, llvm::DenseMap<uint16_t, uint16_t, KeyInfo<uint16_t>>{},
llvm::DenseMap<uint32_t, uint32_t, KeyInfo<uint32_t>>{}, llvm::DenseMap<uint64_t, uint64_t, KeyInfo<uint64_t>>{});
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
return 0;
}