I need to copy the content of one buffer to another one in blocks of n bytes (n might vary), several times to check the cache performance.
I use memcpy, but I'm afraid I'm not getting successful results. The block size is variable from some kbytes to Mbytes. And I have to reserve the maximum block to use (long double).
I'm a little lost in the copy. I'm just wondering if somebody has faced this problem, and can help me with some tips or pseudo code.
I edit the topic to include some code:
int main (int argc, char *argv[])
{
FILE *fp;
fp= fopen("part1.dat", "w");
struct timeval time, oldtime;
float segundos, microsegundos, total;
// float rendimiento;
pid_t pid;
struct sched_param parametros;
int i, v,p;
char buffer1[100024];
char buffer2[100024];
pid = getpid();
parametros.sched_priority = sched_get_priority_max(SCHED_FIFO);
sched_setscheduler(pid, SCHED_FIFO, ¶metros);
p=0;
gettimeofday(&oldtime, NULL);
for (i=1;i<65;i++)
{
size_t datos=i*1024;
for (v=0; p>i;v++)
{
memcpy(buffer1, buffer2, datos);
p=(MAX_SIZE/i*1024);
}
}
gettimeofday(&time, NULL);
segundos = (float) (time.tv_sec - oldtime.tv_sec);
microsegundos = (float) (time.tv_usec - oldtime.tv_usec);
total = (float) ((segundos * 1000000 + microsegundos));
// printf ("Dimension %d \t Tiempo 1: %.2f \t Fallos Metodo 1:%d \t Tiempo 2: %.2f \t Fallos Metodo 2:%d \t Multiplica: %f \t Rendimiento: %.2f\n", i, total, fallos1, total2, fallos2, iteraciones, rendimiento);
// fprintf (fp, "%d \t %.3f %.3f %.3f\n", i, total, total2,rendimiento);
fclose(fp);
printf("Se ha creado el archivo de datos: part1.dat\n");
return(0);
}
The idea is to copy from buffer1 to buffer2, in datos blocks 'p' times, in this case is supposed to be done 256000 times (i=1, datos=1024).