65,210
社区成员
发帖
与我相关
我的任务
分享
void send(char*to, char* from, 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);
}
}
#include <windows.h>
#include <stdio.h>
#define SIZE 2*1024
void memcpy_8(char*to, char* from, int count)
{
if(from==NULL||to==NULL||count==0)
return ;
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);
}
}
void *memcpy_char(void *to, void *from, int count)
{
char *p1,*p2;
p1 = (char*)to;
p2 = (char*)from;
while(count-->0)
{
*p1++ = *p2++;
}
return to;
}
void *memcpy_int(void *to, void *from, int count)
{
int *p1,*p2;
char *p3,*p4;
p1 = (int*)to;
p2 = (int*)from;
while (count>3)
{
*p1++ = *p2++;
count -= 4;
}
p3 = (char*)p1;
p4 = (char*)p2;
while (count-->0)
{
*p3++ = *p4++;
}
return to;
}
int main(int argc, char* argv[])
{
char a[SIZE] = "abcdefghijelmnopqrst";
char b[SIZE] = "";
LARGE_INTEGER li1,li2;
QueryPerformanceFrequency(&li1);
double freq = (double)li1.QuadPart;
QueryPerformanceCounter(&li1);
memcpy(b,a,SIZE);
QueryPerformanceCounter(&li2);
printf("memcpy:\t\t%f\n",(li2.QuadPart - li1.QuadPart)/freq);
QueryPerformanceCounter(&li1);
memcpy_char(b,a,SIZE);
QueryPerformanceCounter(&li2);
printf("memcpy_char:\t%f\n",(li2.QuadPart - li1.QuadPart)/freq);
memset(b,0,SIZE);
QueryPerformanceCounter(&li1);
memcpy_int(b,a,SIZE);
QueryPerformanceCounter(&li2);
printf("memcpy_int:\t%f\n",(li2.QuadPart - li1.QuadPart)/freq);
QueryPerformanceCounter(&li1);
memcpy_8(b,a,SIZE);
QueryPerformanceCounter(&li2);
printf("memcpy_8:\t%f\n",(li2.QuadPart - li1.QuadPart)/freq);
return 0;
}