-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
61 lines (55 loc) · 1.8 KB
/
main.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
#include "BTree.h"
#include "funky.h"
int main() {
srand(time(NULL));
int n = 100000;
int k = insertVal();
BTree b(k);
double sum = 0;
int r;
for (int i = 0; i < n; i++) {
r = rand() % n + 1;
auto start = std::chrono::system_clock::now();
b.insert(r);
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
sum += elapsed_seconds.count();
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
}
std::cout << "Average Time for Insert: " << sum/n << "s\n";
sum = 0;
for (int i = 0; i < 10; i++) {
int r = rand() % n + 1;
BTreeNode* x = b.search(r);
if (x != NULL) {
std::cout << "B-TreeNode* Keys: ";
for (int j = 0; j < x->getNumKeys(); j++) {
std::cout << x->getKey(j) << " ";
}
std::cout << "\n";
}
}
for (int i = 0; i < n/10; i++) {
r = rand() % n + 1;
//std::cout << "Searching key: " << r << "...\n";
auto start = std::chrono::system_clock::now();
BTreeNode* x = b.search(r);
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
sum += elapsed_seconds.count();
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
}
std::cout << "Average Time for Search: " << sum/(n/10) << "s\n";
for (int i = 0; i < n/10; i++) {
r = rand() % n + 1;
//std::cout << "Deleting key: " << r << "...\n";
auto start = std::chrono::system_clock::now();
b.remove(r);
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
sum += elapsed_seconds.count();
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
}
std::cout << "Average Time for Deletion: " << sum/(n/10) << "s\n";
return 0;
}