-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.cc
60 lines (55 loc) · 1.66 KB
/
test.cc
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
#include <chrono>
#include <iostream>
#include "bplus_tree.h"
int main(int argc, char const* argv[]) {
(void)argc;
(void)argv;
srand(time(0));
BPlusTree bpt("test.db");
char k[33];
char v[101];
for (int n = 10000; n <= 1000000; n *= 10) {
std::cout << "----------------------------------------------------"
<< "\n";
auto t1 = std::chrono::steady_clock::now();
// Random Insert
for (int i = 0; i < n; ++i) {
int r = rand() % n;
snprintf(k, 33, "k%d", r);
snprintf(v, 101, "v%d", r);
bpt.Put(k, v);
}
auto t2 = std::chrono::steady_clock::now();
std::cout << "Random Insert " << n << " items: time span="
<< std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1)
.count()
<< "ms"
<< "\n";
// Random Find
for (int i = 0; i < n; ++i) {
int r = rand() % n;
snprintf(k, 33, "k%d", r);
std::string value;
bpt.Get(k, value);
}
auto t3 = std::chrono::steady_clock::now();
std::cout << "Random Get " << n << " items: time span="
<< std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t2)
.count()
<< "ms"
<< "\n";
// Random Delete
for (int i = 0; i < n; ++i) {
int r = rand() % n;
snprintf(k, 33, "k%d", r);
bpt.Delete(k);
}
auto t4 = std::chrono::steady_clock::now();
std::cout << "Random Delete " << n << " items: time span="
<< std::chrono::duration_cast<std::chrono::milliseconds>(t4 - t3)
.count()
<< "ms"
<< "\n";
}
return 0;
}