-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
137 lines (103 loc) · 2.43 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
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
#include <iostream>
#include <string>
#include <memory>
#include <algorithm>
#include "AtomicEvent.h"
#include "Event.h"
#include <vector>
#include "ALadderQueue.h"
#include <iomanip>
#include <random>
#include <queue>
#include <ctime>
#include "main.h"
#include <fstream>
#include <cstdlib>
constexpr auto SIZE = 5000000;
using std::ofstream;
using namespace std;
using std::cerr;
using std::endl;
void testALQ(std::vector<double> list) {
ALadderQueue ladder;
//ofstream outdata;
//outdata.open("alq_result.txt"); // opens the file
//if (!outdata) { // file couldn't be opened
// cerr << "Error: file could not be opened" << endl;
// exit(1);
//}
//ofstream enqdata;
//enqdata.open("alq_enqueue.txt"); // opens the file
//if (!enqdata) { // file couldn't be opened
// cerr << "Error: file could not be opened" << endl;
// exit(1);
//}
for (int i = 0; i < SIZE; i++) {
//enqdata << list.back() << endl;
ladder.enqueue(Event(list.back()));
list.pop_back();
}
/*while (list.size() > 0) {
ladder.enqueue(Event(list.back()));
list.pop_back();
ladder.dequeue();
std::cout << "d+enqueued" << "\n";
}*/
//enqdata.close();
int m = 0;
while (ladder.getSize()>0) {
m++;
try {
ladder.dequeue();
}
catch(exception & e){
std::cout << e.what() << "\n";
}
/*if (ladder.getSize() < 5) {
ladder.printStatus();
}*/
}
//outdata.close();
std::cout << "Total dequeue : " << m << "\n";
}
void testPQ(std::vector<double> list) {
priority_queue<double> pq;
for (int i = 0; i < SIZE; i++) {
pq.push(list.back());
list.pop_back();
}
/*while (list.size() > 0) {
pq.push(list.back());
list.pop_back();
pq.pop();
}*/
while (pq.size() > 0) {
pq.pop();
}
}
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
std::exponential_distribution<> d(1.0);
//ofstream outdata;
//outdata.open("list.txt"); // opens the file
//if (!outdata) { // file couldn't be opened
// cerr << "Error: file could not be opened" << endl;
// exit(1);
//}
std::vector<double> list;
for (int n = 0; n < SIZE; n++) {
list.push_back(d(gen));
//outdata <<list.back() << endl;
}
//outdata.close();
std::cout << list.size() << "\n";
clock_t begin_time = clock();
testALQ(list);
std::cout << "ALQ: " << float(clock() - begin_time) / CLOCKS_PER_SEC << "\n";
std::cout << list.size() << "\n";
clock_t begin_time_2 = clock();
testPQ(list);
std::cout << "PQ: " << float(clock() - begin_time_2) / CLOCKS_PER_SEC;
}