-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
137 lines (119 loc) · 3.31 KB
/
main.cpp
File metadata and controls
137 lines (119 loc) · 3.31 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 <iostream>
#include "Graph.hpp"
#include "AtomicGraph.hpp"
#include "GraphMutex.hpp"
#include "GraphSharedMutex.hpp"
#include <thread>
void test1(GraphSharedMutex &graph) {
//Increment
for(int i = 0; i < 25000; i++)
graph.increaseEdge(rand() % 200,rand() % 200);
//Decrement
for(int i = 0; i < 25000; i++)
graph.decreaseEdge(rand() % 200,rand() % 200);
//Delete
for(int i = 0; i < 250; i++)
graph.deleteEdge(rand() % 200, rand() % 200);
//Insert Nodes
for(int i = 0; i < 15; i++)
graph.insertNode();
//Insert Edges
for(int i = 200; i < 215; i++) {
for(int j = 200; j < 215; j++) {
graph.insertEdge(i, j);
}
}
}
void test2(GraphSharedMutex &graph) {
//Decrement
for(int i = 0; i < 25000; i++)
graph.decreaseEdge(rand() % 200,rand() % 200);
//Increment
for(int i = 0; i < 25000; i++)
graph.increaseEdge(rand() % 200,rand() % 200);
//Delete
for(int i = 0; i < 250; i++)
graph.deleteEdge(rand() % 200, rand() % 200);
//Insert Nodes
for(int i = 0; i < 15; i++)
graph.insertNode();
//Insert Edges
for(int i = 200; i < 215; i++) {
for(int j = 200; j < 215; j++) {
graph.insertEdge(i, j);
}
}
}
void test3(GraphSharedMutex &graph) {
//Delete
for(int i = 0; i < 250; i++)
graph.deleteEdge(rand() % 200, rand() % 200);
//Decrement
for(int i = 0; i < 25000; i++)
graph.decreaseEdge(rand() % 200,rand() % 200);
//Increment
for(int i = 0; i < 25000; i++)
graph.increaseEdge(rand() % 200,rand() % 200);
//Insert Nodes
for(int i = 0; i < 15; i++)
graph.insertNode();
//Insert Edges
for(int i = 200; i < 215; i++) {
for(int j = 200; j < 215; j++) {
graph.insertEdge(i, j);
}
}
}
void test4(GraphSharedMutex &graph) {
//Insert Nodes
for(int i = 0; i < 15; i++)
graph.insertNode();
//Insert Edges
for(int i = 200; i < 215; i++) {
for(int j = 200; j < 215; j++) {
graph.insertEdge(i, j);
}
}
//Increment
for(int i = 0; i < 25000; i++)
graph.increaseEdge(rand() % 200,rand() % 200);
//Delete
for(int i = 0; i < 250; i++)
graph.deleteEdge(rand() % 200, rand() % 200);
//Decrement
for(int i = 0; i < 25000; i++)
graph.decreaseEdge(rand() % 200,rand() % 200);
}
int main(){
GraphSharedMutex graph;
//Insert Nodes
for(int i = 0; i < 200; i++)
graph.insertNode();
//Insert Edges
for(int i = 0; i < 200; i++) {
for(int j = 0; j < 200; j++) {
graph.insertEdge(i, j);
}
}
//std::fflush(stdin);
//graph.printEdges();
auto t1 = std::thread(test1, std::ref(graph));
auto t2 = std::thread(test2, std::ref(graph));
auto t3 = std::thread(test3, std::ref(graph));
auto t4 = std::thread(test4, std::ref(graph));
auto t5 = std::thread(test1, std::ref(graph));
auto t6 = std::thread(test2, std::ref(graph));
auto t7 = std::thread(test3, std::ref(graph));
auto t8 = std::thread(test4, std::ref(graph));
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
t6.join();
t7.join();
t8.join();
//std::fflush(stdin);
//graph.printEdges();
return 0;
}