9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: mirtchov@cpsc.ucalgary.ca
To: 9fans@cse.psu.edu
Subject: [9fans] "ridiculous benchmarks"-r-us
Date: Fri,  9 Jan 2004 10:42:49 -0700	[thread overview]
Message-ID: <0af7b239ace45c567f28524ff95b5613@plan9.ucalgary.ca> (raw)

[-- Attachment #1: Type: text/plain, Size: 3357 bytes --]

Rog at vitanuova already caught how stupid the following article is
(linked to from slashdot):

	http://osnews.com/story.php?news_id=5602

It took me much longer -- until I looked at their "C" code (term used
very loosely) trying to compile it on Plan 9...  There are multiple
gems in it including ++ on a double, mid-function variable definitions
(C-code, right?), log10(0.0), impossible to look at I/O, etc.  In
fact, I'm attaching the benchmark for your viewing pleasure :)

Anyway, the exercise took very little time and here are some "results"
showing how good Plan 9's compiler are (where's a Bushnell when you
need one?), it would be interesting to see how the long arithmetic can be improved:

pcc (code untouched except for mid-function variable definitions moved to top):

	Int arithmetic elapsed time: 17540 ms with intMax of 1000000000
	 i: 1000000001
	 intResult: 1
	Double arithmetic elapsed time: 65500 ms with doubleMin 10000000000.000000, doubleMax 11000000000.000000
	 i: 11000000000.000000
	 doubleResult: 10011632717.495501
	Long arithmetic elapsed time: 262540 ms with longMin I64d, longMax I64d
	 i: I64d
	 longResult: I64d
	Trig elapsed time: 25070 ms with max of 10000000
	 i: 10000000.000000
	 sine: 0.990665
	 cosine: -0.136322
	 tangent: -7.267119
	 logarithm: 7.000000
	 squareRoot: 3162.277502
	[crashes during the last test while reading back the file it just wrote]

gcc (code untouched, no -O):

	Int arithmetic elapsed time: 23770 ms with intMax of 1000000000
	 i: 1000000001
	 intResult: 1
	Double arithmetic elapsed time: 56040 ms with doubleMin 10000000000.000000, doubleMax 11000000000.000000
	 i: 11000000000.000000
	 doubleResult: 10011632717.495501
	Long arithmetic elapsed time: 53500 ms with longMin I64d, longMax I64d
	 i: I64d
	 longResult: I64d
	Trig elapsed time: 30680 ms with max of 10000000
	 i: 10000000.000000
	 sine: 0.990665
	 cosine: -0.136322
	 tangent: -7.267119
	 logarithm: 7.000000
	 squareRoot: 3162.277502
	[crashes during the last test while reading back the file it just wrote]

8c (modified to use nsec() for timing, printf -> print, fixed log10(0.0) crash, fix %I64d in print()):

	Int arithmetic elapsed time: 17517 ms with intMax of 1000000000
	 i: 1000000001
	 intResult: 1
	Double arithmetic elapsed time: 22525 ms with doubleMin 10000000000.000000, doubleMax 11000000000.000000
	 i: 11000000000.000000
	 doubleResult: 10011632717.495500
	Long arithmetic elapsed time: 565067 ms with longMin 10000000000, longMax 11000000000
	 i: 11000000000
	 longResult: 776627965
	Trig elapsed time: 25881 ms with max of 10000000
	 i: 10000000.100000
	 sine: 0.972106
	 cosine: -0.234542
	 tangent: -4.144701
	 logarithm: 7.000000
	 squareRoot: 3162.277518


It is important to note that the integer performance of 8c is
comparable to gcc 3.3's -O[23] running on Plan 9 and Linux
respectively.  The double arithmetic lags by about 20%.  The I/O is
comparable (2x slower when going over a 100mbit link, no caching).

Profiling the long long code to see where it looses all that time may
be interesting.

All computation performed on a 8-way 700mhz Xeon, only 1 cpu used :)

Sorry for wasting your time -- just wanted to see how good 8c was and
got caught in all the other crap. It's Friday after all... :)

Andrey

[-- Attachment #2: Benchmark.c --]
[-- Type: text/plain, Size: 4494 bytes --]

/* All code Copyright 2004 Christopher W. Cowell-Shah */

#include <time.h>
#include <math.h>
#include <stdio.h>

double intArithmetic(int);
double doubleArithmetic(double, double);
double longArithmetic(long long int, long long int);
double trig(double);
double io(int);

int main()
{
	int intMax =            1000000000; // 1B
	double doubleMin =      10000000000.0; // 10B
	double doubleMax =      11000000000.0; // 11B
	long long int longMin = 10000000000LL; // 10B
	long long int longMax = 11000000000LL; // 11B
	double trigMax =        10000000; // 10M
	int ioMax =             1000000; // 1M


	printf("Start C benchmark\n");

	long intArithmeticTime = (long)intArithmetic(intMax);
	long doubleArithmeticTime = (long)doubleArithmetic(doubleMin, doubleMax);
	long longArithmeticTime = (long)longArithmetic(longMin, longMax);
	long trigTime = (long)trig(trigMax);
	long ioTime = (long)io(ioMax);
	long totalTime = intArithmeticTime + doubleArithmeticTime + longArithmeticTime + trigTime + ioTime;
	printf("Total elapsed time: %d ms\n", totalTime);

	printf("Stop C benchmark\n");
	return 0;
}


double intArithmetic(int intMax)
{
	double elapsedTime;
	clock_t stopTime;
	clock_t startTime = clock();

	int intResult = 1;
	int i = 1;
	while (i < intMax)
	{
		intResult -= i++;
		intResult += i++;
		intResult *= i++;
		intResult /= i++;
	}

	stopTime = clock();
	elapsedTime = (stopTime - startTime) / (CLOCKS_PER_SEC / (double) 1000.0);
	printf("Int arithmetic elapsed time: %1.0f ms with intMax of %ld\n", elapsedTime, intMax);
	printf(" i: %d\n", i);
	printf(" intResult: %d\n", intResult);
	return elapsedTime;
}


double doubleArithmetic(double doubleMin, double doubleMax)
{
	double elapsedTime;
	clock_t stopTime;
	clock_t startTime = clock();

	double doubleResult = doubleMin;
	double i = doubleMin;
	while (i < doubleMax)
	{
		doubleResult -= i++;
		doubleResult += i++;
		doubleResult *= i++;
		doubleResult /= i++;
	}

	stopTime = clock();
	elapsedTime = (stopTime - startTime) / (CLOCKS_PER_SEC / (double) 1000.0);
	printf("Double arithmetic elapsed time: %1.0f ms with doubleMin %f, doubleMax %f\n", elapsedTime, doubleMin, doubleMax);
	printf(" i: %f\n", i);
	printf(" doubleResult: %f\n", doubleResult);
	return elapsedTime;
}


double longArithmetic(long long int longMin, long long int longMax)
{
	double elapsedTime;
	clock_t stopTime;
	clock_t startTime = clock();

	long long longResult = longMin;
	long long i = longMin;
	while (i < longMax)
	{
		longResult -= i++;
		longResult += i++;
		longResult *= i++;
		longResult /= i++;
	}

	stopTime = clock();
	elapsedTime = (stopTime - startTime) / (CLOCKS_PER_SEC / (double) 1000.0);
	printf("Long arithmetic elapsed time: %1.0f ms with longMin %I64d, longMax %I64d\n", elapsedTime, longMin, longMax);
	printf(" i: %I64d\n", i);
	printf(" longResult: %I64d\n", longResult);
	return elapsedTime;
}


double trig(double trigMax)
{
	double elapsedTime;
	clock_t stopTime;
	clock_t startTime = clock();

	double sine;
	double cosine;
	double tangent;
	double logarithm;
	double squareRoot;

	double i = 0.0;
	while (i < trigMax)
	{
		sine = sin(i);
		cosine = cos(i);
		tangent = tan(i);
		logarithm = log10(i);
		squareRoot = sqrt(i);
		i++;
	}

	stopTime = clock();
	elapsedTime = (stopTime - startTime) / (CLOCKS_PER_SEC / (double) 1000.0);
	printf("Trig elapsed time: %1.0f ms with max of %1.0f\n", elapsedTime, trigMax);
	printf(" i: %f\n", i);
	printf(" sine: %f\n", sine);
	printf(" cosine: %f\n", cosine);
	printf(" tangent: %f\n", tangent);
	printf(" logarithm: %f\n", logarithm);
	printf(" squareRoot: %f\n", squareRoot);
	return elapsedTime;
}


double io(int ioMax)
{
	double elapsedTime;
	clock_t stopTime;
	clock_t startTime = clock();

	FILE *stream;
	stream = fopen("C:\\TestGcc.txt", "w");
	int i = 0;
	while (i++ < ioMax)
	{
		fputs("abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefgh\n", stream);
	}
	fclose(stream);

	char readLine[100];
	stream = fopen("C:\\TestGcc.txt", "r");
	i = 0;
	while (i++ < ioMax)
	{
		fgets(readLine, 100, stream);
	}
	fclose(stream);

	stopTime = clock();
	elapsedTime = (stopTime - startTime) / (CLOCKS_PER_SEC / (double) 1000.0);
	printf("I/O elapsed time: %1.0f ms with max of %d\n", elapsedTime, ioMax);
	printf(" last line: %s", readLine);

	return elapsedTime;
}

             reply	other threads:[~2004-01-09 17:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-09 17:42 mirtchov [this message]
2004-01-09 17:47 ` ron minnich
2004-01-09 18:19 ` Icarus Sparry
2004-01-09 18:37   ` mirtchov
2004-01-09 20:25     ` Sam
2004-01-09 20:29       ` Charles Forsyth
2004-01-09 20:44         ` Sam
2004-01-09 20:44         ` Brantley Coile
2004-01-10  0:37           ` Dennis Ritchie
2004-01-09 20:48         ` mirtchov
2004-01-11  1:02     ` [9fans] 'ridiculous benchmarks'-r-us Joel Salomon
2004-01-09 18:52   ` [9fans] "ridiculous benchmarks"-r-us Brantley Coile
2004-01-09 20:06     ` Tristan Seligmann
2004-01-10  5:06     ` boyd, rounin
2004-01-09 19:40 ` Roman Shaposhnick
2004-01-09 20:54 ` Atanas Bachvaroff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0af7b239ace45c567f28524ff95b5613@plan9.ucalgary.ca \
    --to=mirtchov@cpsc.ucalgary.ca \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).