home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 28
/
amigaformatcd28.iso
/
-seriously_amiga-
/
misc
/
posbb
/
src
/
generic
/
mem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-05-09
|
2KB
|
120 lines
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* #include "posbb_tests.h" // this would be needed by Test_qsort,not finished,yet
*/
#define TRUE -1
#define FALSE 0
/****** posbb_tests.c/Test_CopyMem ******************************************
*
* NAME
* Test_CopyMem -- Tests speed of memcpy()
*
* SYNOPSIS
* time = Test_CopyMem( void )
*
* int Test_CopyMem( void );
*
* FUNCTION
* Does 100,000 CopyMem() of a 1024 bytes memory block and returns the
* time it has spent.
*
* RESULT
* time - number of seconds it took to do all memory copies.
* TRUE if something went wrong (usually lack of memory).
*
* EXAMPLE
* Examine posbb.c/Perform_Tests().
*
****************************************************************************
*/
int Test_CopyMem( precision )
int precision;
{
time_t time1,time2;
long *mem1,*mem2;
long ret=-1,c;
if (mem1=(long *) malloc(1024))
{
if (mem2=(long *) malloc(1024))
{
time1 = time(NULL);
for ( c = 0; c<(100000 * precision); c++ )
{
memcpy(mem2,mem1,1024);
}
time2 = time(NULL);
free(mem1);
free(mem2);
return (time2-time1);
}
else return TRUE;
}
else return TRUE;
}
int Test_CopyMem_1Mb( precision )
int precision;
{
time_t time1,time2;
long *mem1,*mem2;
long ret=-1,c;
if (mem1=(long *) malloc(1024*1024))
{
if (mem2=(long *) malloc(1024*1024))
{
time1 = time(NULL);
for ( c = 0; c<(100 * precision); c++ )
{
memcpy(mem2,mem1,1024*1024);
}
time2 = time(NULL);
free(mem1);
free(mem2);
return (time2-time1);
}
else return TRUE;
}
else return TRUE;
}
int Test_CopyMem_512kb( precision )
int precision;
{
time_t time1,time2;
long *mem1,*mem2;
long ret=-1,c;
if (mem1=(long *) malloc(512*1024))
{
if (mem2=(long *) malloc(512*1024))
{
time1 = time(NULL);
for ( c = 0; c<(200 * precision); c++ )
{
memcpy(mem2,mem1,512*1024);
}
time2 = time(NULL);
free(mem1);
free(mem2);
return (time2-time1);
}
else return TRUE;
}
else return TRUE;
}