-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.cpp
More file actions
156 lines (128 loc) · 4.83 KB
/
Copy pathtest3.cpp
File metadata and controls
156 lines (128 loc) · 4.83 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include "Arr.h"
using namespace std;
using namespace chrono;
int main(){
int ind1 = 3;
int ind2 = 2;
int ind3 = 1;
int num = 1;
cout << "Hello World" << endl;
int a1[5] = {num,2,4,num,1};
Arr<int> aa1{a1, 5};
cout << "built in arr:";
for (int i=0; i<5; i++){cout << " " << a1[i];}
cout << endl;
cout << aa1 << endl;
cout << "() Indexing: ";
cout << aa1(4) << endl;
size_t N_repeat = 100000;
cout << endl <<"N_repeat: " << N_repeat << endl;
cout << endl <<" built-in[] | Arr [] | Arr () | Arr [] x | Arr () x | () vs [] | units " << endl;
auto t_start = high_resolution_clock::now();
auto t_end = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
auto tempDur = duration.count()*1000;
auto tempDur2 = duration.count()*1000;
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=a1[ind1];
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
cout << " " << 1000*duration.count();
tempDur=duration.count()*1000;
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=aa1[ind1];
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
tempDur2=duration.count()*1000;
cout << " | " << 1000*duration.count();
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=aa1(ind1);
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
cout << " | " << 1000*duration.count();
cout << " | " << tempDur2/tempDur;
cout << " | " << 1000*duration.count()/tempDur;
cout << " | " << 1000*duration.count()/tempDur2 << " | nanoseconds." << endl;
int a2[3][5] = {{num,2,3,4,5},{5,9,1,8,5},{1,3,6,num,5}};
size_t shap2[2] = {3,5};
Arr<int, 2> aa2{a2[0], shap2};
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=a2[ind2][ind1];
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
cout << " " << 1000*duration.count();
tempDur=duration.count()*1000;
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=aa2[ind2][ind1];
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
tempDur2=duration.count()*1000;
cout << " | " << 1000*duration.count();
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=aa2(ind2, ind1);
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
cout << " | " << 1000*duration.count();
cout << " | " << tempDur2/tempDur;
cout << " | " << 1000*duration.count()/tempDur;
cout << " | " << 1000*duration.count()/tempDur2 << " | nanoseconds." << endl;
int a3[2][3][4] = {{{num,1,1,1},{1,1,1,1},{1,1,1,1}},{{2,2,2,2},{2,2,2,2},{2,2,2,num}}};
size_t shap3[3] = {2,3,4};
Arr<int,3> aa3{a3[0][0], shap3};
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=a3[ind3][ind2][ind1];
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
cout << " " << 1000*duration.count();
tempDur=duration.count()*1000;
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=aa3[ind3][ind2][ind1];
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
tempDur2=duration.count()*1000;
cout << " | " << 1000*duration.count();
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=aa3(ind3, ind2, ind1);
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
cout << " | " << 1000*duration.count();
cout << " | " << tempDur2/tempDur;
cout << " | " << 1000*duration.count()/tempDur;
cout << " | " << 1000*duration.count()/tempDur2 << " | nanoseconds." << endl;
int* b1 = new int[4]{num, 1,1,1};
int* b2 = new int[4]{1,1,1,1};
int* b3 = new int[4]{1,1,1,1};
int* b4 = new int[4]{2,2,2,2};
int* b5 = new int[4]{2,2,2,2};
int* b6 = new int[4]{2,2,2,num};
int** bb1 = new int*[4]{b1, b2, b3};
int** bb2 = new int*[4]{b4, b5, b6};
int*** bbb1 = new int**[2]{bb1, bb2};
t_start = high_resolution_clock::now();
for (int i=0; i<N_repeat;){
i+=bbb1[ind3][ind2][ind1];
}
t_end = high_resolution_clock::now();
duration = duration_cast<microseconds>(t_end - t_start)/(double)N_repeat;
cout << "\n " << 1000*duration.count() << endl;;
cout << aa2(aa2<7) << endl;
}