Newsgroups: comp.arch
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!linus!linus!news
From: bs@gauss.mitre.org (Robert D. Silverman)
Subject: Small Benchmark
Message-ID: <1991May17.181628.19207@linus.mitre.org>
Sender: news@linus.mitre.org (News Service)
Nntp-Posting-Host: gauss.mitre.org
Organization: The MITRE Corporation, Bedford MA 10730
Date: Fri, 17 May 1991 18:16:28 GMT

I would like to present the following (small) benchmark code for Unix
systems. A co-worker has dubbed this 'bobstones'.

This program very seriously tests memory and data cacheing effects. It is
quite simple. 

I would like to ask that people out there try this out and report the results
back to this forum. It only takes a few seconds to run.
 
This code is taken from a real application that spends 50% of its time 
in the loop given below.

#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
char sieve[3000000];			/* sieve array: 3 megabytes	*/
 
main()
{
int i,j,k;
int loc;
struct rusage ru;
double tots,totu;

for (i=0; i<20000; i++)	 {		/* for 20,000 different strides	*/
   j = 10*i + 1;		/* compute length of this stride	*/
   loc = 3;			/* starting location in the array	*/
   while (loc < 3000000)	/* starting at 'loc', add 1 to every	*/
	{			/* j'th location in the array		*/
	sieve[loc] += 1;
	loc += j;
	}
   }
   getrusage(RUSAGE_SELF,&ru);
   totu = ru.ru_utime.tv_sec + ((double) ru.ru_utime.tv_usec / 1000000.);
   tots = ru.ru_stime.tv_sec + ((double) ru.ru_stime.tv_usec / 1000000.);
   printf("Total time (sys+user)       :\t%.2lf  (bobstones)\n", totu + tots);
   printf("Page faults (min/maj)       :\t%d/%d\n",ru.ru_minflt,ru.ru_majflt);
   printf("Blocks in input/output      :\t%d/%d\n",ru.ru_inblock,ru.ru_oublock);
   printf("Context switches (vol/invol):\t%d/%d\n",ru.ru_nvcsw,ru.ru_nivcsw);
}

--
Bob Silverman
#include <std.disclaimer>
Mitre Corporation, Bedford, MA 01730
"You can lead a horse's ass to knowledge, but you can't make him think"
