[net.sources.mac] Harmonic Series Benchmark

jimb@amd.UUCP (Jim Budler) (05/27/85)

In response to a posting on arpanet I wrote this program to duplicate
the test. The time to do the sum of the first 10,000 terms of the
harmonic series.  The poster said that Megamax C took the longest,
I don't remember the time, Aztec took 36 seconds, MacForth took 9
seconds, and MacFortran took 4 seconds.
He also said only Aztec gave the correct answer 9.787613.
Well Consulair Mac C 2.0 took 29 seconds using floats and got the 
right answer.  Mac C 2.0 took 29 seconds to give the answer using 
doubles, and gave the answer as 9.787606, which was the same answer
givem by an IBM 3081.
Using Mac C 2.0's extended 80 bit precision reduced the time to
25 seconds by eliminating type conversions. Answer, 9.787606 .
"I" think Mac C did quite well on this test.
Here's the program:
------------------------< cut here >------------------------------
#!/bin/sh
echo 'Start of harmonic.c, part 01 of 01:'
echo 'x - harmonicMac.c'
sed 's/^X//' > harmonicMac.c << '/'
X#include "stdio.h"
X#include "sane.h"
X#Options D=300
X// To make it fit 128K Mac
X
Xmain() /* compute some floating point times */
X{
Xchar *outfile = "harmonic output";
Xlong ticks;
Xextended seconds;
Xint fd = open(outfile, 1);
Xfprintf(fd,"Calculating the sum of 10,000 terms of the harmonic series\n");
Xfprintf(fd,"Vax 11/780 with FPU took 0.02 seconds the answer was 9.787613\n");
Xfprintf(fd,"This result from originator of problem. Assumed \"right\" answer.\n");
Xprintf("Calculating the sum of 10,000 terms of the harmonic series\n");
Xprintf("Vax 11/780 with FPU took 0.02 seconds the answer was 9.787613\n");
Xprintf("This result from originator of problem. Assumed \"right\" answer.\n");
Xregister int i;
Xregister float j = 0;
X    {
X    printf("\nThis is a Macintosh with Consulair Mac C 2.0,\n");
X    printf("using float, 32 bit precision:\n");
X    fprintf(fd,"\nThis is a Macintosh with Consulair Mac C 2.0,\n");
X    fprintf(fd,"using float, 32 bit precision:\n");
X    ticks = -TickCount();
X    for  ( i=1; i <= 10000; i++ )
X    	j += ( 1.0 / i );
X    ticks += TickCount();
X    seconds = (extended)ticks/60;
X    printf("\nTime = %d.%d Seconds",
X    	ticks/60, (((ticks % 60) * 100)+30)/60);
X    printf("\tSum = %f\n", j);
X    fprintf(fd,"\nTime = %d.%d Seconds",
X    	ticks/60, (((ticks % 60) * 100)+30)/60);
X    fprintf(fd,"\tSum = %f\n", j);
X    }
Xregister double k = 0;
X    {
X	printf("\nUsing Doubles:\n");
X	printf("IBM3081 with UST System III took 0.00? seconds,\n");
X	printf("\tthe answer was 9.787606.\n");
X	printf("A Valid 68000 CAD workstation 4.1c BSD took 23 seconds,\n");
X	printf("\tthe answer was 9.787606.\n");
X	fprintf(fd,"\nUsing Doubles:\n");
X	fprintf(fd,"IBM3081 with UST System III took 0.00? seconds,\n");
X	fprintf(fd,"\tthe answer was 9.787606.\n");
X	fprintf(fd,"A Valid 68000 CAD workstation 4.1c BSD took 23 seconds,\n");
X	fprintf(fd,"\tthe answer was 9.787606.\n");
X    printf("\nThis is a Macintosh with Consulair Mac C 2.0,\n");
X    printf("using double, 64 bit precision:\n");
X    fprintf(fd,"\nThis is a Macintosh with Consulair Mac C 2.0,\n");
X    fprintf(fd,"using double, 64 bit precision:\n");
X    ticks = -TickCount();
X    for  ( i=1; i <= 10000; i++ )
X    	k += ( 1.0 / i );
X    ticks += TickCount();
X    seconds = (extended)ticks/60;
X    printf("\nTime = %d.%d Seconds",
X    	ticks/60, (((ticks % 60) * 100)+30)/60);
X    printf("\tSum = %lf\n", k);
X    fprintf(fd,"\nTime = %d.%d Seconds",
X    	ticks/60, (((ticks % 60) * 100)+30)/60);
X    fprintf(fd,"\tSum = %lf\n", k);
X    }
X    register extended e = 0;
X    {
X	printf("\nBill Duvall of Consulair recommends using extended,\n");
X	printf("80 bit precision for computation with Mac C as that is the\n");
X	printf("base mode of his implemntation of the SANE/IEEE numerics.\n");
X	fprintf(fd,"\nBill Duvall of Consulair recommends using extended,\n");
X	fprintf(fd,"80 bit precision for computation with Mac C as that is the\n");
X	fprintf(fd,"base mode of his implemntation of the SANE/IEEE numerics.\n");
X    printf("\nThis is a Macintosh with Consulair Mac C 2.0,\n");
X    printf("using extended, 80 bit precision:\n");
X    fprintf(fd,"\nThis is a Macintosh with Consulair Mac C 2.0,\n");
X    fprintf(fd,"using extended, 80 bit precision:\n");
X    ticks = -TickCount();
X    for  ( i=1; i <= 10000; i++ )
X    	e += ( 1.0 / i );
X    ticks += TickCount();
X    seconds = (extended)ticks/60;
X    printf("\nTime = %d.%d Seconds",
X    	ticks/60, (((ticks % 60) * 100)+30)/60);
X    printf("\tSum = %f\n", e);
X    fprintf(fd,"\nTime = %d.%d Seconds",
X    	ticks/60, (((ticks % 60) * 100)+30)/60);
X    fprintf(fd,"\tSum = %f\n", e);
X    }
X    close(fd);
X  SetFileType(outfile, (long) 'TEXT');
X  getchar();
X  exit(0);
X  }
/
echo 'Part 01 of harmonic.c complete.'
exit
-- 
 Jim Budler
 Advanced Micro Devices, Inc.
 (408) 749-5806
 UUCPnet: {ucbvax,decwrl,ihnp4,allegra,intelca}!amdcad!jimb
 Compuserve:	72415,1200