
Hey, guys, I just realized this test is not really fair! I've been using the Microsoft .Net compiler ,which is a proprietary closed-source compiler. To be fair to Haskell, we should probably compare it to other open source products, such as g++ and mono? Here are the timings ;-) Haskell ====== J:\dev\haskell>ghc -O2 -o primechaddai.exe PrimeChaddai.hs J:\dev\haskell>primechaddai number of primes: 664579 Elapsed time: 26.234 g++ === J:\dev\test\testperf>g++ -O2 -o prime.exe prime.cpp J:\dev\test\testperf>prime number of primes: 664579 elapsed time: 0.984 mono ==== J:\dev\test\testperf>erase primecs.exe J:\dev\test\testperf>gmcs primecs.cs J:\dev\test\testperf>mono primecs.exe number of primes: 664579 elapsed time: 0,719 Microsoft C# ========= J:\dev\test\testperf>csc /nologo primecs.cs J:\dev\test\testperf>primecs number of primes: 664579 elapsed time: 0,6875 Not only does mono come close to the Microsoft .Net time, both mono and Microsoft .Net are faster than g++ ;-) and whack Haskell. Here's the C++ code for completeness: #include <iostream> #include <ctime> using namespace std; int CalculateNumberOfPrimes( int maxprime ) { bool *IsPrime = new bool[ maxprime ]; for( int i = 0; i < maxprime; i++ ) { IsPrime[i] = true; } int NumberOfPrimes = 0; for( int i = 2; i < maxprime; i++ ) { if( IsPrime[i] ) { NumberOfPrimes++; for( int j = ( i << 1 ); j < maxprime; j+= i ) { IsPrime[ j] = false; } } } return NumberOfPrimes; } int main( int argc, char *argv[] ) { clock_t start = clock(); int NumberOfPrimes = CalculateNumberOfPrimes( 10000000 ); cout << "number of primes: " << NumberOfPrimes << endl; clock_t finish = clock(); double time = (double(finish)-double(start))/CLOCKS_PER_SEC; cout << "elapsed time: " << time << endl; return 0; }