Skip to content

Commit 2ea66f2

Browse files
committed
Report updated
1 parent 907d3ac commit 2ea66f2

File tree

3 files changed

+541
-565
lines changed

3 files changed

+541
-565
lines changed

Turlikov/Report_2/dop_task/main.cpp

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -81,74 +81,50 @@ int main() {
8181
// алгоритм с делением
8282
cout << endl << "func: 1" << endl;
8383
for (int bit = 0; bit < 64; bit++) {
84-
int64_t duration = 0;
85-
for (int i = 0; i < ITERS; i++) {
86-
int64_t n = (1LL << bit) + rand() % (1LL << bit);
87-
auto t1 = high_resolution_clock::now();
88-
// ---- //
89-
count_ones_1(n);
90-
// ---- //
91-
auto t2 = high_resolution_clock::now();
92-
duration += duration_cast<microseconds>(t2 - t1).count();
93-
}
94-
cout << "bit: " << bit + 1
95-
<< " dur: " << (double) duration / ITERS << " us"
96-
<< endl;
84+
int64_t n = (1LL << bit); // + rand() % (1LL << bit);
85+
auto t1 = high_resolution_clock::now();
86+
for (int i = 0; i < ITERS; i++, count_ones_1(n));
87+
auto t2 = high_resolution_clock::now();
88+
uint64_t duration = duration_cast<microseconds>(t2 - t1).count();
89+
cout << "bit: " << bit + 1;
90+
cout << "\tdur: " << (double) duration / ITERS << " us\n";
9791
}
9892

9993
// алгоритм с побитовыми операциями
10094
cout << endl << "func: 2" << endl;
10195
for (int bit = 0; bit < 64; bit++) {
102-
int64_t duration = 0;
103-
for (int i = 0; i < ITERS; i++) {
104-
int64_t n = (1LL << bit) + rand() % (1LL << bit);
105-
auto t1 = high_resolution_clock::now();
106-
// ---- //
107-
count_ones_2(n);
108-
// ---- //
109-
auto t2 = high_resolution_clock::now();
110-
duration += duration_cast<microseconds>(t2 - t1).count();
111-
}
112-
cout << "bit: " << bit + 1
113-
<< " dur: " << (double) duration / ITERS << " us"
114-
<< endl;
96+
int64_t n = (1LL << bit); // + rand() % (1LL << bit);
97+
auto t1 = high_resolution_clock::now();
98+
for (int i = 0; i < ITERS; i++, count_ones_2(n));
99+
auto t2 = high_resolution_clock::now();
100+
uint64_t duration = duration_cast<microseconds>(t2 - t1).count();
101+
cout << "bit: " << bit + 1;
102+
cout << "\tdur: " << (double) duration / ITERS << " us\n";
115103
}
116104

117105
// алгоритм со вспомогательной таблицей (маленькой)
118106
cout << endl << "func: 3" << endl;
119107
for (int bit = 0; bit < 64; bit++) {
120-
int64_t duration = 0;
121-
for (int i = 0; i < ITERS; i++) {
122-
int64_t n = (1LL << bit) + rand() % (1LL << bit);
123-
auto t1 = high_resolution_clock::now();
124-
// ---- //
125-
count_ones_3(n);
126-
// ---- //
127-
auto t2 = high_resolution_clock::now();
128-
duration += duration_cast<microseconds>(t2 - t1).count();
129-
}
130-
cout << "bit: " << bit + 1
131-
<< " dur: " << (double) duration / ITERS << " us"
132-
<< endl;
108+
int64_t n = (1LL << bit); // + rand() % (1LL << bit);
109+
auto t1 = high_resolution_clock::now();
110+
for (int i = 0; i < ITERS; i++, count_ones_3(n));
111+
auto t2 = high_resolution_clock::now();
112+
uint64_t duration = duration_cast<microseconds>(t2 - t1).count();
113+
cout << "bit: " << bit + 1;
114+
cout << "\tdur: " << (double) duration / ITERS << " us\n";
133115
}
134116

135117
// алгоритм со вспомогательной таблицей (большой)
136118
cout << endl << "func: 4" << endl;
137119
for (int bit = 0; bit < 64; bit++) {
138-
int64_t duration = 0;
139-
for (int i = 0; i < ITERS; i++) {
140-
int64_t n = (1LL << bit) + rand() % (1LL << bit);
141-
auto t1 = high_resolution_clock::now();
142-
// ---- //
143-
count_ones_4(n);
144-
// ---- //
145-
auto t2 = high_resolution_clock::now();
146-
duration += duration_cast<microseconds>(t2 - t1).count();
147-
}
148-
cout << "bit: " << bit + 1
149-
<< " dur: " << (double) duration / ITERS << " us"
150-
<< endl;
120+
int64_t n = (1LL << bit); // + rand() % (1LL << bit);
121+
auto t1 = high_resolution_clock::now();
122+
for (int i = 0; i < ITERS; i++, count_ones_4(n));
123+
auto t2 = high_resolution_clock::now();
124+
uint64_t duration = duration_cast<microseconds>(t2 - t1).count();
125+
cout << "bit: " << bit + 1;
126+
cout << "\tdur: " << (double) duration / ITERS << " us\n";
151127
}
152128

153129
return 0;
154-
}
130+
}

0 commit comments

Comments
 (0)