-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduff.c
50 lines (40 loc) · 1.35 KB
/
duff.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
#include <string.h>
#include <stdio.h>
#include "hr_time.h"
#define COUNT 10025
// ----------------------------------------------------------------------------
static void send(short* to, short* from, const int count);
// ----------------------------------------------------------------------------
int main(){
static short to[COUNT];
static short from[COUNT];
HRWatch WDuff, WMcpy;
for(int i=0; i<COUNT; i++){
from[i] = (short)i;
}
StartTimer(&WDuff);
send(to, from, COUNT);
StopTimer(&WDuff);
printf("Calc timing Duff device : %f (sec.)\n", GetElapsedTime(&WDuff));
StartTimer(&WMcpy);
memcpy(to, from, COUNT*sizeof(short));
StopTimer(&WMcpy);
printf("Calc timing mem copy : %f (sec.)\n", GetElapsedTime(&WMcpy));
getchar();
}
// ----------------------------------------------------------------------------
static void send(short *to, short *from, const int count){
int n = (count + 7) / 8;
switch(count % 8) {
case 0: do { *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
} while(--n > 0);
}
return;
}