From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <0af7b239ace45c567f28524ff95b5613@plan9.ucalgary.ca> To: 9fans@cse.psu.edu From: mirtchov@cpsc.ucalgary.ca MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-pinjdhzulusgqolethreeuxkao" Subject: [9fans] "ridiculous benchmarks"-r-us Date: Fri, 9 Jan 2004 10:42:49 -0700 Topicbox-Message-UUID: b4d17b60-eacc-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-pinjdhzulusgqolethreeuxkao Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit 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 --upas-pinjdhzulusgqolethreeuxkao Content-Disposition: attachment; filename=Benchmark.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit /* All code Copyright 2004 Christopher W. Cowell-Shah */ #include #include #include 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; } --upas-pinjdhzulusgqolethreeuxkao--