[net.micro.amiga] Memory Speed Test Program

perry@picuxa.UUCP (Perry S. Kivolowitz) (07/23/86)

The following program will  measure  raw  memory  speed. The program is
to be compiled under Manx C and run from the CLI with no other programs
running. This will compare  your  internal  memory (when it isn't being
used to refresh a HIRES or 5 bit  plane image) to the external memory.

I will post results for the Alegra memory board soon.

Perry S. Kivolowitz
-----------------------------------------------------------------------

#include <exec/types.h>
#include <intuition/intuition.h>
#include <exec/memory.h>

/*
**	ram-speed
**
**	Times memory performance. To be compiled under MANX.
**
**	Author:	Perry S. Kivolowitz
**
*/

extern  char			*AllocMem();
extern  struct IntuitionBase	*OpenLibrary();

struct  IntuitionBase		*IntuitionBase;

char    *source , *destination;
long    EndingSeconds , EndingMicroSeconds;
long    StartingSeconds , StartingMicroSeconds;

#define	BSIZE			(1L << 17)

/*
**	FreeAll
**
**	Return any allocated memory back to the system for reuse.
**
*/

FreeAll()
{
	if (source) FreeMem(source , BSIZE);
	if (destination) FreeMem(destination , BSIZE);
}

/*
**	AllocAll
**
**	Given a type of memory specified by ``bits'' allocate BSIZE
**	bytes for a source area and a destination area.
**
*/

AllocAll(bits)
long bits;
{
	destination = AllocMem(BSIZE , bits);
	source      = AllocMem(BSIZE , bits);
	if (!source || !destination) {
		printf("Allocation of Memory Failed\n");
		Leave();
	}
}

/*
**	Leave
**
**	Clean up routine. Release memory and close Intuition.
**
*/

Leave()
{
	FreeAll();
	CloseLibrary(IntuitionBase);
	exit(0);
}

OpenIntuition()
{
	IntuitionBase = OpenLibrary("intuition.library" , 0L);
	if (!IntuitionBase) {
		printf("Could Not Open Intuition\n");
		exit(0);
	}
}

long PrintTime()
{
	long temp1 , temp2;

	temp2 = 1000000 * EndingSeconds + EndingMicroSeconds;
	temp1 = 1000000 * StartingSeconds + StartingMicroSeconds;
	temp2 = temp2 - temp1;
	printf("Elapsed Time (microseconds): %ld\n" , temp2);
	return(temp2);
}

long TimeRam(bits)
long bits;
{
	AllocAll(bits);
	CurrentTime(&StartingSeconds , &StartingMicroSeconds);
	CopyRam();
	CurrentTime(&EndingSeconds , &EndingMicroSeconds);
	FreeAll();
	return(PrintTime());
}

main()
{
	int i;
	long fast , chip;

	OpenIntuition();
	printf("Timing CHIP Memory\n");
	chip = TimeRam(MEMF_CHIP);
	printf("Timing FAST Memory\n");
	fast = TimeRam(MEMF_FAST);
	printf("Difference (microseconds): %ld\n" , fast - chip);
	Leave();
}

CopyRam()
{
	register long *src , *dst;
	register short i , j;

	for (j = 0; j < 256; j++) {
		src = (long *) source;
		dst = (long *) destination;
		i = BSIZE / 32;
		while (--i) {
#asm
			move.l	(a2)+,(a3)+
			move.l	(a2)+,(a3)+
			move.l	(a2)+,(a3)+
			move.l	(a2)+,(a3)+
			move.l	(a2)+,(a3)+
			move.l	(a2)+,(a3)+
			move.l	(a2)+,(a3)+
			move.l	(a2)+,(a3)+
#endasm
		}
	}
}