home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 28
/
amigaformatcd28.iso
/
-seriously_amiga-
/
misc
/
posbb
/
src
/
generic
/
posbb_tests.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-05-09
|
9KB
|
442 lines
/* This is the include file containing the code
for the tests of the generic version.
Most of autodoc's text among functions is that of some old Amiga version,
so something could be wrong.
*/
/****** posbb_tests.c/--background-- ***************************************
*
* These are the functions wich really do tests. All them returns
* the time taken in seconds.
*
****************************************************************************
*/
#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;
}
/****** posbb_tests.c/Test_printf ******************************************
*
* NAME
* Test_printf -- Tests the speed of the ANSI function printf().
*
* SYNOPSIS
* time = Test_printf( void )
* int Test_printf( void );
*
* FUNCTION
* Writes 1,000 times the string "printf test in progress...\n" to stdout
* and returns the time taken.
*
* RESULT
* time - number of seconds taken. No error possible.
*
* EXAMPLE
* See posbb.c/Perform_Tests().
*
* BUGS
* It hasn't bugs,but since it can't turn off multitasking,the result
* could change if the user runs some program or move windows.
*
****************************************************************************
*/
int Test_printf( precision )
int precision;
{
int c;
time_t time1,time2;
time1 = time(NULL);
for ( c = 0; c<1000*precision; c++ )
{
printf("printf test in progress...\n");
}
time2 = time(NULL);
return (time2-time1);
}
/****** posbb_tests.c/Test_IMath ********************************************
*
* NAME
* Test_IMath -- Tests the speed of some int Math operations.
*
* SYNOPSIS
* time = Test_IMath( void )
* BYTE Test_IMath( void );
*
* FUNCTION
* Does 1 million of additions,differences,multiplications and divisions
* and returns the time it took.
*
* RESULT
* time - number of seconds taken. No error can be returned.
*
* EXAMPLE
* See posbb.c/Perform_Tests()
**
****************************************************************************
*/
int Test_IMath( precision )
int precision;
{
int c,i=0;
long *a=0,*b=0,*d=0;
time_t time1,time2;
a = calloc(sizeof(long),100*precision);
b = calloc(sizeof(long),100*precision);
d = calloc(sizeof(long),100*precision);
/* Initializing b and d table with random values */
for(i =0;i<(100*precision);i++)
{
b[i] = rand();
d[i] = rand();
}
time1 = time(NULL);
for (c = 0;c<10000;c++)
{
for ( i = 0; i<(100 * precision)-3; i+=3 )
{
a[i] /= b[i] + d[i];
a[i+1] *= b[i+1] - d[i+1];
a[i+2] += b[i+2] * d[i+2];
a[i+3] -= b[i+3] / d[i+3];
}
}
time2 = time(NULL);
free(a);
free(b);
free(d);
return (time2-time1);
}
int Test_FPMath( precision )
int precision;
{
int c,i=0;
double *a=0,*b,*d;
time_t time1,time2;
a = calloc(sizeof(double),100*precision);
b = calloc(sizeof(double),100*precision);
d = calloc(sizeof(double),100*precision);
/* Initializing b and d table with random values; */
for(c =0;c<(100*precision);c++) {
b[c] = (double) rand();
d[c] = (double) rand();
}
time1 = time(NULL);
for (c = 0;c<10000;c++)
{
for ( i = 0; i<(100 * precision)-3; i+=3 )
{
a[i] /= b[i] + d[i];
a[i+1] *= b[i+1] - d[i+1];
a[i+2] += b[i+2] * d[i+2];
a[i+3] -= b[i+3] / d[i+3];
}
}
time2 = time(NULL);
free(a);
free(b);
free(d);
return (time2-time1);
}
/****** posbb_tests.c/Test_Write ********************************************
*
* NAME
* Test_Write -- Tests disk writing speed.
*
* SYNOPSIS
* time = Test_Write( void )
* int Test_Write( void );
*
* FUNCTION
* Writes a block of data to a file,with dos.library/Write() (in the Amiga
* version).
*
* INPUT
* Now void,in future versions a STRPTR,the name of the file to write to.
*
* RESULT
* time - Number of seconds taken.
* Returns TRUE if something went wrong ( memory or disk space usually).
* In future may return differents error codes.
*
* EXAMPLE
* See posbb.c/Perform_Tests.
*
* BUGS
* No known bugs.
*
****************************************************************************
*/
/*
int Test_Write( void )
{
int clk;
int c;
long buf;
BPTR file;
if ( buf=AllocMem(262144,NULL))
{
Forbid();
( int ) time1 = time(NULL);
if (( BPTR ) file = Open("RAM:POSBB_TestFile",( ULONG ) MODE_NEWFILE))
{
Write(file,buf,262144);
Close(file);
( int ) time1 = time(NULL);
Permit();
FreeMem(buf,262144);
}
}
if (file = NULL) return TRUE;
else return (clk);
}
*/
/****** posbb_tests.c/Test_Read ********************************************
*
* This section of the autodoc isn't finished. See Test_Write().
* The function doesn't works in the generic version,yet.
*
*******
*/
/* This is the Amiga one
int Test_Read( void )
{
int clk;
long buf;
BPTR file = NULL;
if ( buf = AllocMem((262144),0))
{
Forbid();
( int ) time1 = time(NULL);
if ( ( BPTR ) file = Open("RAM:POSBB_TestFile",MODE_OLDFILE) )
{
Read(file,buf,262144);
( int ) l2= clock();
Permit();
Close(file);
}
FreeMem(buf,262144);
}
if (file = NULL) return TRUE;
else return (clk);
}
*/
/****** posbb_tests.c/Test_WritePixel **************************************
*
* This function doesn't work.In the generic version.
*
********
*/
/*
int strsrt(s1,s2) // this function is needed by Test_qsort,but I'll change them
char *s1,*s2;
{
return (s1[1]-s2[1]);
}
int Test_qsort(precision) // This test isn't finished,yet. It doesn't work but I should change it.
int precision;
{
int c;
time_t time1,time2;
time1 = time(NULL);
qsort(StrList,15,sizeof(char *),strsrt);
time2 = time(NULL);
for (c = 0;c<15;c++)
{
printf("%d %s\n",c,StrList[c]);
}
return (time2-time1);
}
*/
int Test_TMath(precision)
int precision;
{
time_t time1,time2;
int c=0;
double *cosine=0,*sine=0,*tangent=0,angle = 0;
cosine = calloc(sizeof(double),360*precision);
sine = calloc(sizeof(double),360*precision);
tangent = calloc(sizeof(double),360*precision);
time1 = time(NULL);
for(c=0;c<100;c++)
{
for(angle=0;angle<360*precision;angle++)
{
sine[(int)angle] = sin(angle);
cosine[(int)angle] = cos(angle);
tangent[(int)angle] = tan(angle);
}
}
time2 = time(NULL);
free(sine);
free(cosine);
free(tangent);
return (time2-time1);
}
/****** posbb_tests.c/Test_CopyMem_1MB ******************************************
*
* NAME
* Test_CopyMem -- Tests speed of memcpy()
*
* SYNOPSIS
* time = Test_CopyMem( void )
*
* int Test_CopyMem( void );
*
* FUNCTION
* Does 100 CopyMem() of a 1024 kbytes 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_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;
}