-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest5.cc
More file actions
40 lines (35 loc) · 1.16 KB
/
test5.cc
File metadata and controls
40 lines (35 loc) · 1.16 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
#include "main.h"
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
// Get some timing results
void test5 ()
{
const size_t M = 2048;
const size_t N = 2048;
const size_t K = 31;
vector<int> x (M * N);
// draw random values from a normal distribution
default_random_engine e;
std::normal_distribution<> n (0, 10);
auto f = [&] { return n (e); };
generate (begin (x), end (x), f);
// compute rms contrast slow
auto start_time = chrono::high_resolution_clock::now ();
vector<int> y = slow_average (x, M, N, K);
auto end_time = chrono::high_resolution_clock::now ();
auto t1 = chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count ();
cout << "t1: " << t1 << "ms" << endl;
// compute rms contrast fast
start_time = chrono::high_resolution_clock::now ();
y = fast_average (x, M, N, K);
end_time = chrono::high_resolution_clock::now ();
auto t2 = chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count ();
cout << "t2: " << t2 << "ms" << endl;
cout << static_cast<double> (t1) / t2 << "X speedup" << endl;
}
void process ()
{
test5 ();
}