[Haskell-cafe] how to make haskell faster than python at finding
alex at alexjacobson.com
Mon Aug 6 04:22:26 EDT 2007
Thought perhaps the problem is that modcount is just a slower algorithm.
... nevermind. Thanks.
Alex Jacobson wrote:
> The challenge was the implement the modcount algorithm not to calculate
> primes per se.
> (see e.g. http://jjinux.blogspot.com/2005/11/io-comparison.html).
> Donald Bruce Stewart wrote:
>>> This implementation of calculating 10000 primes (compiled with GHC
>>> -O2) is 25% slower than the naive python implementation. Shouldn't
>>> it be faster? Am I doing something obviously stupid?
>> Why not just:
>> primes = sieve [2..]
>> sieve (p : xs) = p : sieve [x | x <- xs, x `mod` p > 0]
>> main = print (take 1000 primes)
>> That's super naive, and seems to be around 5x faster than the code you
>> trying. (So make sure you're doing the same thing as the python version)
>> -- Don
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe