Even with your values I still have problems with this :
#include #include #include
#define BIG_SIZE 64000000
int main(int argc, char **argv) { int i, j; int32_t *mem; int32_t *pmem; int16_t *b; int16_t *pb; struct timeval *start_timeval; struct timeval *current_timeval; unsigned long lstart_usecs, lcurrent_usecs, ldiff_usecs;
fprintf(stderr, "memory needed=%d MB\\n", ( (BIG_SIZE * sizeof (int32_t) ) + (BIG_SIZE * sizeof(int16_t) ) ) / 1000000 );
mem = (int32_t*)malloc(BIG_SIZE * sizeof(int32_t) ); if(! mem) { fprintf(stderr, "could not allocate space for mem, aborting.\\n"); exit(1); }
b = (int16_t*)malloc(BIG_SIZE * sizeof(int16_t) ); if(! b) { fprintf(stderr, "could not allocate space for b, aborting.\\n"); exit(1); }
fprintf(stderr, "mem=%p\\n", mem); fprintf(stderr, "b=%p\\n", b);
start_timeval = malloc(sizeof(struct timeval) ); if(! start_timeval) { fprintf(stderr, "could not allocate space for start_timeval, aborting.\\n");
exit(1); }
current_timeval = malloc(sizeof(struct timeval) ); if(! start_timeval) { fprintf(stderr, "could not allocate space for current_timeval, aborting.\\n");
exit(1); }
/* get start time */ gettimeofday(start_timeval, NULL);
for(j = 0; j < 10; j++) { pmem = mem; pb = b;
for(i = 0; i < BIG_SIZE; i++) { *pmem += *pb;
pmem++; pb++; } }
/* get elapsed time */ gettimeofday(current_timeval, NULL);
/* calculate the difference */ lcurrent_usecs =\\ current_timeval -> tv_usec + (1000000 * current_timeval -> tv_sec);
lstart_usecs =\\ start_timeval -> tv_usec + (1000000 * start_timeval -> tv_sec);
ldiff_usecs = lcurrent_usecs - lstart_usecs;
fprintf(stderr, "Time used is %d us (%.4f s).\\n", ldiff_usecs, (float) ldiff_usecs / 1000000.0);
fprintf(stderr, "Ready\\n");
exit(0); }
When I run that on the eeePC with 512MB RAM, I get these times:
eeepc-unknown:/root> ./test2 memory needed=384 MB mem=0xa8a54008 b=0xa1041008 Time used is 13920337 us (13.9203 s). Ready
Run repeatedly.