-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpeedTest.cpp
More file actions
56 lines (45 loc) · 1.23 KB
/
SpeedTest.cpp
File metadata and controls
56 lines (45 loc) · 1.23 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
#include <cstdlib>
#include <ctime>
#include <iostream>
#include "RedBlackTree.h"
using namespace std;
int main(){
// create a simulated 3.7 million ID number system.
const int N = 3700000;
clock_t start = clock();
RedBlackTree rbt = RedBlackTree();
for(int i = 0; i < N; i++){
rbt.Insert(i);
}
clock_t stop = clock();
double duration = (static_cast<double>(stop - start)) / CLOCKS_PER_SEC;
cout << "Collected " << rbt.Size() << " ID numbers in " << (duration) << " seconds." << endl;
// Your code goes here to simulate leaving / joining.
int numInsert = 0;
int numRemove = 0;
while (numInsert < 5 || numRemove < 5) {
int num = rand();
duration = 0.0;
if (rbt.Contains(num)) {
if (numRemove < 5) {
numRemove++;
start = clock();
rbt.Remove(num);
stop = clock();
duration = (static_cast<double>(stop - start)) / CLOCKS_PER_SEC;
cout << "Removing " << num << " takes " << duration << " seconds" << endl;
}
}
else {
if (numInsert < 5) {
numInsert++;
start = clock();
rbt.Insert(num);
stop = clock();
duration = (static_cast<double>(stop - start)) / CLOCKS_PER_SEC;
cout << "Inserting " << num << " takes " << duration << " seconds" << endl;
}
}
}
return 0;
}