-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathticks.c
More file actions
97 lines (68 loc) · 1.61 KB
/
Copy pathticks.c
File metadata and controls
97 lines (68 loc) · 1.61 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
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
93
94
95
96
97
/*
Clock Tick counter for sum and sub instructions
Author Dario Clavijo 2016
GPLv3
*/
#include <time.h>
void test_clock(){
clock_t start, end;
int cpu_time_used;
start = clock();
/* Do the work. */
end = clock();
cpu_time_used = ((double) (end - start));
printf("Clocks: %d\n",cpu_time_used);
}
#define STEP 65535
#define MAX_ITER CLOCKS_PER_SEC * 1000
int test_sum(){
clock_t start, end;
int cpu_time_used;
unsigned int j=0;
start = clock();
/* Do the work. */
for(int i=0;i<=MAX_ITER;i++){
j+=STEP;
}
end = clock();
cpu_time_used = ((double) (end - start));
printf("sum clocks: %d\n",cpu_time_used);
return cpu_time_used;
}
int test_sub(){
clock_t start, end;
int cpu_time_used;
unsigned int j=MAX_ITER;
start = clock();
/* Do the work. */
for(int i=0;i<=MAX_ITER;i++){
j-=STEP;
}
end = clock();
cpu_time_used = ((double) (end - start));
printf("sub clocks: %d\n",cpu_time_used);
return cpu_time_used;
}
int test_mul(){
clock_t start, end;
int cpu_time_used;
unsigned int j=MAX_ITER;
start = clock();
/* Do the work. */
for(int i=0;i<=MAX_ITER;i++){
j = (i * 65535);
}
end = clock();
cpu_time_used = ((double) (end - start));
printf("mul clocks: %d\n",cpu_time_used);
return cpu_time_used;
}
int main(){
printf("clocks per sec: %d\n",CLOCKS_PER_SEC);
printf("Max Iterations: %d\n",MAX_ITER);
printf("step: %d\n",STEP);
int t1 = test_sum();
int t2 = test_sub();
int t3 = test_mul();
//printf("diff: %d\n",(t1-t2));
}