K
Kevin Wan
Hello,
Would anyone explain why there is a consistent large performance
degradation with the dumb copy?
Thanks in advance!
array_copy_dumb.c:
/* array_copy_dumb.c */
#define DUMBCOPY for (i = 0; i < 65536; ++i) destination =
source
int main(void)
{
char source[65536], destination[65536];
int i, j;
for (j = 0; j < 100; ++j)
DUMBCOPY; /* 1 */
return 0;
}
array_copy_smart.c:
/* array_copy_smart.c */
#include <string.h>
#define SMARTCOPY memcpy(destination, source, 65536)
int main(void)
{
char source[65536], destination[65536];
int i, j;
for (j = 0; j < 100; ++j)
SMARTCOPY;
return 0;
}
$ gcc -O3 array_copy_dumb.c -o array_copy_dumb
$ time array_copy_dumb
real 4.99
user 4.86
sys 0.00
$ gcc -O3 array_copy_smart.c -o array_copy_smart
$ time array_copy_smart
real 0.15
user 0.15
sys 0.00
I just know it's due to cache! But would anyone explain it in detail?
Thanks again!
Would anyone explain why there is a consistent large performance
degradation with the dumb copy?
Thanks in advance!
array_copy_dumb.c:
/* array_copy_dumb.c */
#define DUMBCOPY for (i = 0; i < 65536; ++i) destination =
source
int main(void)
{
char source[65536], destination[65536];
int i, j;
for (j = 0; j < 100; ++j)
DUMBCOPY; /* 1 */
return 0;
}
array_copy_smart.c:
/* array_copy_smart.c */
#include <string.h>
#define SMARTCOPY memcpy(destination, source, 65536)
int main(void)
{
char source[65536], destination[65536];
int i, j;
for (j = 0; j < 100; ++j)
SMARTCOPY;
return 0;
}
$ gcc -O3 array_copy_dumb.c -o array_copy_dumb
$ time array_copy_dumb
real 4.99
user 4.86
sys 0.00
$ gcc -O3 array_copy_smart.c -o array_copy_smart
$ time array_copy_smart
real 0.15
user 0.15
sys 0.00
I just know it's due to cache! But would anyone explain it in detail?
Thanks again!