-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_lavastone.cpp
101 lines (89 loc) · 3.89 KB
/
test_lavastone.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
#include "gendata.hpp"
#include "lavapack.hpp"
// this must be invoked once to allow (de)serialization of this struct type
LAVAPACK_ADAPT_STRUCT(recipe, title, author, author_location, num_likes);
#include "lavastone.hpp"
#include <chrono>
#include <iostream>
#include <string>
#define demand(cond, str) \
if (!(cond)) { \
std::cout << str << std::endl; \
exit(1); \
}
#define timeit(code, str) \
{ \
auto start = std::chrono::steady_clock::now(); \
code; \
auto end = std::chrono::steady_clock::now(); \
std::cout << str \
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - \
start) \
.count() \
<< "\n"; \
}
int main(int argc, char *argv[]) {
// test of disk-backed data types
lava::init();
size_t num_records;
if (argc != 2) {
num_records = 10000;
std::cout << "using default of " << num_records << " records\n";
} else {
num_records = std::stoi(argv[1]);
std::cout << "using " << num_records << " records\n";
}
demand(num_records > 0, "no records to test with!");
auto recipes = random_recipes(num_records);
std::unordered_map<std::string, std::unordered_map<int, std::vector<recipe>>>
name_to_num_likes_to_recipes;
lava::Ref<decltype(name_to_num_likes_to_recipes)>
name_to_num_likes_to_recipes_ref;
lava::Ref<decltype(recipes)> recipes_ref;
timeit(recipes_ref = recipes;, "vector_bulk_insert_disk_ms=");
timeit(
for (auto r
: recipes) {
name_to_num_likes_to_recipes[r.author][r.num_likes].push_back(r);
},
"map_random_insert_memory_ms=");
timeit(
for (auto r
: recipes) {
name_to_num_likes_to_recipes_ref[r.author][r.num_likes].push_back(r);
},
"map_random_insert_disk_ms=");
lava::Ref<decltype(name_to_num_likes_to_recipes)>
name_to_num_likes_to_recipes_ref_bulk;
timeit(name_to_num_likes_to_recipes_ref_bulk = name_to_num_likes_to_recipes;
, "map_bulk_memory_to_disk_ms=");
decltype(name_to_num_likes_to_recipes) recovered_1;
timeit(recovered_1 = name_to_num_likes_to_recipes_ref;
, "map_bulk_disk_to_memory_ms=");
decltype(name_to_num_likes_to_recipes) recovered_2 =
name_to_num_likes_to_recipes_ref_bulk;
assert(recovered_1 == recovered_2 &&
recovered_2 == name_to_num_likes_to_recipes);
size_t total_chars = 0;
timeit(
for (size_t i = 0; i < num_records; i++) {
size_t j = std::rand() % num_records;
std::vector<recipe> some_recipes =
name_to_num_likes_to_recipes[recipes[j].author]
[recipes[j].num_likes];
for (auto r : some_recipes)
total_chars += r.title.size();
},
"map_random_access_memory_ms=");
timeit(
for (size_t i = 0; i < num_records; i++) {
size_t j = std::rand() % num_records;
std::vector<recipe> some_recipes =
name_to_num_likes_to_recipes_ref[recipes[j].author]
[recipes[j].num_likes];
for (auto r : some_recipes)
total_chars += r.title.size();
},
"map_random_access_disk_ms=");
std::cout << "total_chars = " << total_chars << "\n";
}