-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhamt.cpp
More file actions
89 lines (62 loc) · 1.82 KB
/
hamt.cpp
File metadata and controls
89 lines (62 loc) · 1.82 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
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "hamt.hpp"
#include <iostream>
#include <chrono>
#include <map>
#include <unordered_map>
#include <vector>
template<class Action, class Resolution = std::chrono::milliseconds,
class Clock = std::chrono::high_resolution_clock>
static double time(Action action) {
typename Clock::time_point start = Clock::now();
action();
typename Clock::time_point stop = Clock::now();
std::chrono::duration<double> res = stop - start;
return res.count();
}
template<class T, std::size_t B, std::size_t L>
static void test_ordered(std::size_t size) {
std::cout << "vector: " << time([=] {
std::vector<T> values;
for(std::size_t i = 0; i < size; ++i) {
values.emplace_back(i);
}
return values.size();
}) << std::endl;
std::cout << "map: " << time([=] {
std::map<std::size_t, T> values;
for(std::size_t i = 0; i < size; ++i) {
values.emplace(i, i);
}
return values.size();
}) << std::endl;
std::cout << "unordered_map: " << time([=] {
std::unordered_map<std::size_t, T> values;
for(std::size_t i = 0; i < size; ++i) {
values.emplace(i, i);
}
return values.size();
}) << std::endl;
std::cout << "hamt: " << time([=] {
hamt::array<T, B, L> values;
for(std::size_t i = 0; i < size; ++i) {
values = values.set(i, i);
}
}) << std::endl;
std::cout << "hamt emplace: " << time([=] {
hamt::array<T, B, L> values;
for(std::size_t i = 0; i < size; ++i) {
values = std::move(values).set(i, i);
}
}) << std::endl;
}
int main(int, char**) {
//
hamt::array<double, 5, 5> test;
test = test.set(0, 1);
std::clog << test.find(0) << std::endl;
std::clog << test.find(1) << std::endl;
test_ordered<double, 5, 4>(10000);
hamt::map<void*, double, 5, 5> map;
map = map.set(nullptr, 0);
return 0;
}