DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦80aec4c50⟧ TextFile

    Length: 5354 (0x14ea)
    Types: TextFile
    Names: »mem.c«

Derivation

└─⟦db229ac7e⟧ Bits:30007240 EUUGD20: SSBA 1.2 / AFW Benchmarks
    └─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21E/musbus/mem.c« 
    └─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21F/musbus/mem.c« 

TextFile

/*
 * mem [ -ssize ] [ -niter ]
 *
 *  perform int array accesses
 *  array size (if given) is in Kbytes, default is 8K
 *  iter accesses of each type, default is iter=100000
 *  Configuration options
 *  #ifdef random	random access
 *  #ifndef random	sequential access
 *  #ifdef awk		output on stderr for benchmark script
 *
 *  #ifdef BSD4v1	4.1 BSD, ftime() exists
 *  #ifdef BSD4v2	4.2 BSD, gettimeofday() exists
 *  #ifdef SysV		System V, times() returns real time in (1/HZ)th of sec
 *
 *  $Header: mem.c,v 5.2 88/01/12 06:06:44 kenj Exp $
 */

#include <stdio.h>
#include "musbus.h"

#include <sys/types.h>
#include <sys/times.h>
#ifdef BSD4v1
#include <sys/timeb.h>
#endif
#ifdef BSD4v2
#include <sys/time.h>
#include <sys/resource.h>
#endif
#ifdef SysV
long	times();
#endif

main(argc, argv)
int argc;
char *argv[];
{
	int		*tab;
        register char	*p;
        register long	i;
        register long	j;
        register long	mask;
        register int	k;
	long		iter = 100000L;
	long		size = 8*1024 / sizeof(int);
	struct tms	tbuffer;
	long		access[2];
	long		ohead[2];
	long		atol();
#ifdef BSD4v1
	struct timeb	tbuf;
	int		msec;
#endif
#ifdef BSD4v2
	struct timeval	tbuf;
	struct timezone	tzone;
	struct rusage	rubuf;
	long		rusec, cpusec;
#endif
	char		*prog = argv[0];
        char            *malloc();
#ifdef random
	long		index[1000];
#endif

        while (argc-- > 1) {
                switch (argv[1][1]) {
                case 's':
                        size = atol(&argv[1][2])*1024 / sizeof(int);
                        break;
                case 'n':
                        iter = atol(&argv[1][2]);
                        break;
                default:
                        printf("Usage: %s [-ssize] [-niter]\n", prog);
                        exit(1);
                }
                argv++;
        }

        mask = size;

        if ((tab = (int *)malloc(size*sizeof(int))) == (int *)0) {
                printf("%s: malloc failed for %ld bytes\n", prog, size*sizeof(int));
                exit(1);
        }

#ifdef random
	/* build random array index map */
	for (i = 0; i < 1000; i++)
		index[i] = rand() % mask;
#endif

        /* measure overhead for loop */
	srand(1);
#ifdef SysV
        ohead[0] = -times(&tbuffer);
	ohead[1] = -tbuffer.tms_utime - tbuffer.tms_stime;
#else
#ifdef BSD4v1
        times(&tbuffer);
	ftime(&tbuf);
	ohead[0] = -tbuf.time;
	msec = tbuf.millitm;
	ohead[1] = -tbuffer.tms_utime - tbuffer.tms_stime;
#else
#ifdef BSD4v2
	gettimeofday(&tbuf, &tzone);
	getrusage(RUSAGE_SELF, &rubuf);
	ohead[0] = -tbuf.tv_sec;
	rusec = tbuf.tv_usec;
	ohead[1] = -rubuf.ru_utime.tv_sec - rubuf.ru_stime.tv_sec;
	cpusec = rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec;
#else
	What sort of Unix system if this?
#endif
#endif
#endif
        for (i = 0, k = 0; i < iter; i++, k++) {
#ifdef random
		if (k >= 1000) k = 0;
                j = index[k];
#else
		if (k >= mask) k = 0;
		j = k;
#endif
	}
#ifdef SysV
	ohead[0] += times(&tbuffer);
	ohead[0] = ohead[0]*1000/HZ;	/* convert to millisec */
	ohead[1] += tbuffer.tms_utime + tbuffer.tms_stime;
#else
#ifdef BSD4v1
        times(&tbuffer);
	ftime(&tbuf);
	ohead[0] += tbuf.time;
	ohead[0] = ohead[0]*1000 + tbuf.millitm - msec;
	ohead[1] += tbuffer.tms_utime + tbuffer.tms_stime;
#else
#ifdef BSD4v2
	gettimeofday(&tbuf, &tzone);
	getrusage(RUSAGE_SELF, &rubuf);
	ohead[0] += tbuf.tv_sec;
	ohead[0] = ohead[0]*1000 + (tbuf.tv_usec - rusec)/1000;
	ohead[1] += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
	ohead[1] = ohead[1]*60 + 60*(rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec - cpusec)/1000000;
#endif
#endif
#endif
	srand(j);	/* use value from loop to fool clever optimizers */
        
        /* perform accesses */
	srand(1);
#ifdef SysV
        access[0] = -times(&tbuffer);
	access[1] = -tbuffer.tms_utime - tbuffer.tms_stime;
#else
#ifdef BSD4v1
        times(&tbuffer);
	ftime(&tbuf);
	access[0] = -tbuf.time;
	msec = tbuf.millitm;
	access[1] = -tbuffer.tms_utime - tbuffer.tms_stime;
#else
#ifdef BSD4v2
	gettimeofday(&tbuf, &tzone);
	getrusage(RUSAGE_SELF, &rubuf);
	access[0] = -tbuf.tv_sec;
	rusec = tbuf.tv_usec;
	access[1] = -rubuf.ru_utime.tv_sec - rubuf.ru_stime.tv_sec;
	cpusec = rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec;
#endif
#endif
#endif
        for (i = 0, k = 0; i < iter; i++, k++) {
#ifdef random
		if (k >= 1000) k = 0;
                j = tab[index[k]];
#else
		if (k >= mask) k = 0;
		j = tab[k];
#endif
	}
#ifdef SysV
	access[0] += times(&tbuffer);
	access[0] = access[0]*1000/HZ;	/* convert to millisec */
	access[1] += tbuffer.tms_utime + tbuffer.tms_stime;
#else
#ifdef BSD4v1
        times(&tbuffer);
	ftime(&tbuf);
	access[0] += tbuf.time;
	access[0] = access[0]*1000 + tbuf.millitm - msec;
	access[1] += tbuffer.tms_utime + tbuffer.tms_stime;
#else
#ifdef BSD4v2
	gettimeofday(&tbuf, &tzone);
	getrusage(RUSAGE_SELF, &rubuf);
	access[0] += tbuf.tv_sec;
	access[0] = access[0]*1000 + (tbuf.tv_usec - rusec)/1000;
	access[1] += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec;
	access[1] = access[1]*60 + 60*(rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec - cpusec)/1000000;
#endif
#endif
#endif
#ifdef awk
	fprintf(stderr, "%ld %ld %.3f\n", iter, access[0] - ohead[0],
			((float)(access[1] - ohead[1]))/60);
#endif
	srand(j);	/* use value from loop to fool clever optimizers */

	exit(0);
}