-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark_lavastone.cpp
58 lines (53 loc) · 1.82 KB
/
benchmark_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
#include "gendata.hpp"
#include "lavapack.hpp"
struct reduced_recipe {
std::string title;
int author_id;
int num_likes;
};
LAVAPACK_ADAPT_STRUCT(reduced_recipe, title, author_id, num_likes);
#include "lavastone.hpp"
#include <chrono>
#include <iostream>
#include <string>
#define demand(cond, str) \
if (!(cond)) { \
std::cout << str << std::endl; \
exit(1); \
}
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, int> author_to_id;
std::vector<std::string> authors;
std::vector<reduced_recipe> reduced_recipes;
for (auto r : recipes) {
std::string author = r.author + "," + r.author_location;
int author_id;
auto it = author_to_id.find(author);
if (it == author_to_id.end()) {
author_id = author_to_id.size();
author_to_id[author] = author_id;
authors.push_back(author);
} else {
author_id = it->second;
}
reduced_recipes.push_back(
{.title = r.title, .author_id = author_id, .num_likes = r.num_likes});
}
std::cout << "writing to kvstore via lavastone\n";
lava::Ref<decltype(reduced_recipes)> reduced_recipes_ref;
lava::Ref<decltype(authors)> authors_ref;
reduced_recipes_ref = reduced_recipes;
authors_ref = authors;
}