-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstackprofile.cpp
More file actions
137 lines (107 loc) · 2.71 KB
/
stackprofile.cpp
File metadata and controls
137 lines (107 loc) · 2.71 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "VecStack.h"
#include "LinkedStack.h"
#include "DequeStack.h"
#include <chrono>
#include <iostream>
#include <functional>
using namespace std;
using namespace std::chrono;
#define ARRAY_SIZE 8096
#define MAX_STACK 100000
#define POP_STACK 50000
typedef struct {
int data[ARRAY_SIZE];
} bigArray;
auto
timeFunc(const std::function<void()>& f, const string& name) {
auto start = high_resolution_clock::now();
f();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout << "| " << name << " | " << duration.count() / 1000.0 << " |" << endl;
return duration;
}
template<typename T>
void
addData(Stack<T> & stack) {
for (int i = 0; i < MAX_STACK; i++) {
T b = {};
stack.push(b);
}
for (int i = 0; i < POP_STACK; i++) {
T b = {};
stack.push(b);
stack.pop();
stack.pop();
}
}
template<typename T>
void
fillAndEmpty(Stack<T> & stack) {
for (int i = 0; i < MAX_STACK; i++) {
T b = {};
stack.push(b);
}
while (!stack.empty()) {
stack.pop();
}
}
//template void bigData<bigArray>(Stack<bigArray> &stack);
int main() {
cout << "| Vector Stack | Time (ms) |" << endl;
cout << "|:-------|:------|" << endl;
timeFunc([]() {
VecStack<bigArray> s;
addData(s);
}, "Big data");
timeFunc([]() {
VecStack<bigArray> stack;
fillAndEmpty(stack);
}, "Big data fill and empty");
timeFunc([]() {
VecStack<int> s;
addData(s);
}, "Small data");
timeFunc([]() {
VecStack<int> s;
fillAndEmpty(s);
}, "Small data fill and empty");
cout << endl;
cout << "| Linked List Stack | Time (ms) |" << endl;
cout << "|:-------|:------|" << endl;
timeFunc([]() {
LinkedStack<bigArray> s;
addData(s);
}, "Big data");
timeFunc([]() {
LinkedStack<bigArray> stack;
fillAndEmpty(stack);
}, "Big data fill and empty");
timeFunc([]() {
LinkedStack<int> s;
addData(s);
}, "Small data");
timeFunc([]() {
LinkedStack<int> s;
fillAndEmpty(s);
}, "Small data fill and empty");
cout << endl;
cout << "| Deque Stack | Time (ms) |" << endl;
cout << "|:-------|:------|" << endl;
timeFunc([]() {
DequeStack<bigArray> s;
addData(s);
}, "Big data");
timeFunc([]() {
DequeStack<bigArray> stack;
fillAndEmpty(stack);
}, "Big data fill and empty");
timeFunc([]() {
DequeStack<int> s;
addData(s);
}, "Small data");
timeFunc([]() {
DequeStack<int> s;
fillAndEmpty(s);
}, "Small data fill and empty");
}