1 #include <iostream>
2 #include <time.h>
3
4 using namespace std;
5
6 char buf1[10010] = { 0 };
7 char buf2[10020] = { 0 };
8
9 void *myMemcpy(void *dst,void * const src, size_t len)
10 {
11 uint64_t *dst_u64 = reinterpret_cast<uint64_t *>(dst);
12 uint64_t *src_u64 = reinterpret_cast<uint64_t *>(src);
13 size_t n = len;
14
15 //64位拷贝
16 while (n > sizeof(uint64_t))
17 {
18 *(dst_u64++) = *(src_u64++);
19 n -= sizeof(uint64_t);
20 }
21
22 uint8_t *dst_u8 = reinterpret_cast<uint8_t *>(dst);
23 uint8_t *src_u8 = reinterpret_cast<uint8_t *>(src);
24
25 //8位拷贝
26 while (n)
27 {
28 *dst_u8++ = *src_u8++;
29 n -= sizeof(uint8_t);
30 }
31
32 return dst;
33 }
34
35 int main()
36 {
37 myMemcpy(buf1, buf2, 10000);
38 cout << "Time: " << clock() << endl;
39 getc(stdin);
40 return 0;
41 }