[Haskell-cafe] In-place modification
Jon Harrop
jon at ffconsultancy.com
Sun Jul 15 13:46:42 EDT 2007
On Sunday 15 July 2007 11:19:29 Hugh Perkins wrote:
> Not only does mono come close to the Microsoft .Net time, both mono and
> Microsoft .Net are faster than g++ ;-) and whack Haskell.
This should tell you that your C++ is not very good. This is several times
faster, for example:
#include <iostream>
#include <ctime>
#include <vector>
using namespace std;
int CalculateNumberOfPrimes(int maxprime)
{
vector<bool> NotPrime(maxprime+1);
int NumberOfPrimes = 0;
for (int i = 2; i <= maxprime; i++ )
if (!NotPrime[i])
{
++NumberOfPrimes;
for (int j = 2*i; j <= maxprime; j += i)
if (!NotPrime[j]) NotPrime[j] = true;
}
return NumberOfPrimes;
}
For some reason you were using C-style allocation rather than the C++ STL to
implement a bit vector. The STL implementation is optimized.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e
More information about the Haskell-Cafe
mailing list