-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (75 loc) · 2.15 KB
/
main.cpp
File metadata and controls
86 lines (75 loc) · 2.15 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
#include <iostream>
#include <fstream>
#include <thread>
#include <vector>
#include "key_value_store.h"
#include "fileDB.h"
struct simple_worker {
MapDB &store;
explicit simple_worker(MapDB &store) : store(store) {
}
void operator()(const std::string& id) {
for (int i = 0; i < 10000; i++) {
std::string val = "val" + id + " - " + std::to_string(i);
std::string key = "key" + id + " - " + std::to_string(i);
store.set(val, key);
}
for (int i = 0; i < 10; i++) {
for (int n = 0; n < 10000; n++) {
int number = n % (1000 * (n + 1));
std::string val = "val" + id + " - " + std::to_string(number);
std::string key = "key" + id + " - " + std::to_string(number);
if (key != store.get(val)) {
std::cerr << "Key Value Store returned wrong value. Going to abort." << std::endl;
exit(1);
}
}
}
for (int i = 0; i < 10000; i++) {
std::string val = "val" + id + " - " + std::to_string(i);
store.remove(val);
}
for (int i = 0; i < 10000; i++) {
std::string val = "val" + id + " - " + std::to_string(i);
if (store.get(val) != "\0") {
std::cerr << "Key Value Store returned old value. Going to abort." << std::endl;
exit(2);
}
}
}
};
const int NUMBER_OF_WORKERS = 1;
const int STORE_SIZE = 10;
//int main() {
// MapDB key_value_store(STORE_SIZE);
//
// std::vector<std::thread> workers;
//
// std::cout << "Start workers" << std::endl;
// auto start = std::chrono::system_clock::now();
//
// for (int i = 0; i < NUMBER_OF_WORKERS; i++) {
// simple_worker worker(key_value_store);
// workers.emplace_back(worker, std::to_string(i));
// }
//
// for (auto &worker : workers) {
// worker.join();
// }
//
// auto end = std::chrono::system_clock::now();
// std::chrono::milliseconds duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
// std::cout << "Workers finished after " << duration.count() << " ms" << std::endl;
// getchar();
// return 0;
//}
int main() {
MapDB key_value_store(STORE_SIZE);
for (int i = 0; i < 10; i++) {
std::string val = "val - " + std::to_string(i);
std::string key = "key - " + std::to_string(i);
key_value_store.set(key, val);
}
getchar();
return 0;
}