As we know, in a multi-bytes word computer such as x86/x86_64, it is more efficiently to copy/move a big bulk of memory word by word (4 or 8 bytes per step), than to do so byte by byte.
I'm curious about which way would strncpy/memcpy/memmove do things in, and how do they deal with memory word alignment.
char buf_A[8], buf_B[8];
// I often want to code as this
*(double*)buf_A = *(double*)buf_B;
//in stead of this
strcpy(buf_A, buf_B);
// but it worsen the readability of my codes.
I think all of the opinions and advices on this page are reasonable, but I decide to try a little experiment.
To my surprise, the fastest method isn't the one we expected theoretically.
I tried some code as following.
The result (one of many similar results):
It looks like:
Is it funny?