forked from apolukhin/course-nimble_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm_6.hpp
48 lines (36 loc) · 1.13 KB
/
algorithm_6.hpp
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
#include "util.hpp"
//////////////////////////// TASK 6 ////////////////////////////
struct naive_complex {
int real, im;
naive_complex() {}
naive_complex(const naive_complex& nc)
: real(nc.real)
, im(nc.im)
{}
~naive_complex(){}
};
struct optim_complex { // TASK: Improve
int real, im;
optim_complex() {}
optim_complex(const optim_complex& nc)
: real(nc.real)
, im(nc.im)
{}
~optim_complex() {}
};
//////////////////////////// DETAIL ////////////////////////////
template <class T>
static void copy_speed(benchmark::State& state, const T& /*data_type*/) {
const std::size_t elements_count = state.range();
for (auto _ : state) {
state.PauseTiming();
std::vector<T> d(elements_count);
std::vector<T> dest(elements_count);
state.ResumeTiming();
std::copy(d.cbegin(), d.cend(), dest.begin());
benchmark::DoNotOptimize(d);
benchmark::DoNotOptimize(dest);
}
}
BENCH(copy_speed, naive_copy_speed, naive_complex{})->Range(8, 8 << 10);
BENCH(copy_speed, optim_copy_speed, optim_complex{})->Range(8, 8 << 10);