-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpipeline-perf-mystery.cpp
More file actions
92 lines (30 loc) · 863 Bytes
/
pipeline-perf-mystery.cpp
File metadata and controls
92 lines (30 loc) · 863 Bytes
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
// scroll *way* down for source
#include <algorithm>
#include "timing.h"
#include <stdio.h>
int main()
{
// generate data
const unsigned arraySize = 32768;
int data[arraySize];
for (unsigned c = 0; c < arraySize; ++c)
data[c] = std::rand() % 256;
long long sum = 0;
// test
timestamp_type start, stop;
get_timestamp(&start);
// std::sort(data, data + arraySize);
for (unsigned i = 0; i < 10000; ++i)
{
// primary loop
for (unsigned c = 0; c < arraySize; ++c)
{
if (data[c] >= 128)
sum += data[c];
}
}
get_timestamp(&stop);
printf("elapsed time: %.2f s\n", timestamp_diff_in_seconds(start, stop));
printf("sum: %lld\n", sum);
}
// http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array