-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_time_taken.cpp
More file actions
101 lines (91 loc) · 3.05 KB
/
Copy pathget_time_taken.cpp
File metadata and controls
101 lines (91 loc) · 3.05 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <vector>
#include <string>
#include <chrono>
using namespace std;
vector<vector<int>> get_time_taken(vector<string> data_structures, vector<string> api) {
vector<vector<int>> time_taken;
for(auto ds : data_structures) {
vector<int> time_for_ds;
for(auto method : api) {
auto start = chrono::high_resolution_clock::now();
if(ds == "array") {
DynamicArray array;
if(method == "add(string s)") {
array.append("hello");
}
else if(method == "remove()") {
array.remove("hello");
}
else if(method == "contains()") {
array.contains("hello");
}
else if(method == "size()") {
array.size();
}
else if(method == "print()") {
array.print();
}
}
else if(ds == "linked list") {
LinkedList list;
if(method == "add(string s)") {
list.append("hello");
}
else if(method == "remove()") {
list.remove("hello");
}
else if(method == "contains()") {
list.contains("hello");
}
else if(method == "size()") {
list.size();
}
else if(method == "print()") {
list.print();
}
}
else if(ds == "BST") {
BST tree;
if(method == "add(string s)") {
tree.append("hello");
}
else if(method == "remove()") {
tree.remove("hello");
}
else if(method == "contains()") {
tree.contains("hello");
}
else if(method == "size()") {
tree.size();
}
else if(method == "print()") {
tree.print();
}
}
else if(ds == "hash table") {
HashTable table;
if(method == "add(string s)") {
table.append("hello");
}
else if(method == "remove()") {
table.remove("hello");
}
else if(method == "contains()") {
table.contains("hello");
}
else if(method == "size()") {
table.size();
}
else if(method == "print()") {
table.print();
}
}
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
time_for_ds.push_back(duration.count());
}
time_taken.push_back(time_for_ds);
}
return time_taken;
}