forked from rurban/safeclib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperf_memcpy32_s.c
179 lines (125 loc) · 3.34 KB
/
perf_memcpy32_s.c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* perf_memcpy32_s.c
*/
#include "test_private.h"
#include "safe_mem_lib.h"
#include "perf_private.h"
#define LEN (1024 * 20)
uint32_t mem1[LEN];
uint32_t mem2[LEN];
uint16_t mem3[LEN];
uint16_t mem4[LEN];
static void timing_loop(uint32_t len, uint32_t loops) {
uint32_t i;
uint64_t clock_start;
uint64_t clock_end;
clock_t sl_clock_diff;
clock_t sd_clock_diff;
double sl_clock_dur;
double sd_clock_dur;
len = len * 2;
for (i = 0; i < LEN; i++) {
mem1[i] = 33;
}
for (i = 0; i < LEN; i++) {
mem2[i] = 44;
}
// printf("\n Timing %d byte copy, %u loops \n", len, loops);
/*
* Safe C Lib Routine
*/
clock_start = timer_start();
for (i = 0; i < loops; i++) {
(void)memcpy32_s(mem1, len, mem2, len);
}
clock_end = timer_end();
/*
* Note that background stuff continues to run, i.e. interrupts, so
* we need to compute average time per loop
*/
sl_clock_diff = (clock_end - clock_start) / loops;
/*
* Standard C Routine
*/
clock_start = timer_start();
for (i = 0; i < loops; i++) {
(void)memcpy16_s(mem3, len, mem4, len);
// memcpy(mem1, mem2, len);
}
clock_end = timer_end();
/*
* Note that background stuff continues to run, i.e. interrupts, so
* we need to compute average time per loop
*/
sd_clock_diff = (clock_end - clock_start) / loops;
/* convert to seconds */
sl_clock_dur = ((double)(sl_clock_diff) / CLOCKS_PER_SEC);
sd_clock_dur = ((double)(sd_clock_diff) / CLOCKS_PER_SEC);
printf("%u %u memcpy32_s %1.9f memcpy16_s %1.9f \n", loops, len,
sl_clock_dur, sd_clock_dur);
return;
}
int main(void) {
uint32_t loops;
rsize_t len;
/*--------------------------------------------------*/
printf("\n\n");
loops = 400;
len = 1024;
timing_loop(len, loops);
len = 1024 * 2;
timing_loop(len, loops);
len = 1024 * 3;
timing_loop(len, loops);
len = 1024 * 4;
timing_loop(len, loops);
len = 1024 * 5;
timing_loop(len, loops);
len = 1024 * 6;
timing_loop(len, loops);
len = 1024 * 7;
timing_loop(len, loops);
len = 1024 * 8;
timing_loop(len, loops);
/*--------------------------------------------------*/
printf("\n\n");
loops = 600;
len = 1024;
timing_loop(len, loops);
len = 1024 * 2;
timing_loop(len, loops);
len = 1024 * 3;
timing_loop(len, loops);
len = 1024 * 4;
timing_loop(len, loops);
len = 1024 * 5;
timing_loop(len, loops);
len = 1024 * 6;
timing_loop(len, loops);
len = 1024 * 7;
timing_loop(len, loops);
len = 1024 * 8;
timing_loop(len, loops);
/*--------------------------------------------------*/
printf("\n\n");
loops = 800;
len = 1024;
timing_loop(len, loops);
len = 1024 * 2;
timing_loop(len, loops);
len = 1024 * 3;
timing_loop(len, loops);
len = 1024 * 4;
timing_loop(len, loops);
len = 1024 * 5;
timing_loop(len, loops);
len = 1024 * 6;
timing_loop(len, loops);
len = 1024 * 7;
timing_loop(len, loops);
len = 1024 * 8;
timing_loop(len, loops);
/*--------------------------------------------------*/
/*--------------------------------------------------*/
return (0);
}