-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
36 lines (30 loc) · 842 Bytes
/
main.cpp
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
#include <stdio.h>
#include <time.h>
int original(int x);
int unrolled(int x);
int main() {
int result = 0;
int loop_count = 100000;
int arg = 1000;
struct timespec begin, end;
clock_gettime(CLOCK_MONOTONIC, &begin);
for (int i = 0; i < loop_count; ++i) {
result += original(arg);
}
clock_gettime(CLOCK_MONOTONIC, &end);
printf(
"original(%d): %f ms\n", result,
((end.tv_sec - begin.tv_sec) * 1000000000 + end.tv_nsec - begin.tv_nsec) /
1000000.0f);
result = 0;
clock_gettime(CLOCK_MONOTONIC, &begin);
for (int i = 0; i < loop_count; ++i) {
result += unrolled(arg);
}
clock_gettime(CLOCK_MONOTONIC, &end);
printf(
"unrolled(%d): %f ms\n", result,
((end.tv_sec - begin.tv_sec) * 1000000000 + end.tv_nsec - begin.tv_nsec) /
1000000.0f);
return result;
}