
Thanks Daniel for your response. sieve of Eratosthenes has a very
elegant 1 line implementation thanks to laziness of haskell. Here is
what I came up with
primesSieve = 2:3:5:7:11:(filter (\x->(all (\p-> 0/=(mod x p))
(takeWhile (\p-> p*p<=x) primesSieve))) [13..])
But didn't seem to make a difference in performance. I had missed the
most obvious of things.... that is adding -O2 when compiling.. It gave
a speedup of close to 100 times which was very surprising! .. I
remember people setting some compiler options in the source file
itself. Can you shed some light on that?
Thanks,
Sunil.
On Fri, Aug 19, 2011 at 3:55 PM, Daniel Fischer
On Friday 19 August 2011, 12:02:30, Sunil S Nandihalli wrote:
Hello everybody, I am a newbie to haskell. I was wondering if there are things I need to do to make the following code faster.
From a short look, you'll probably need a faster prime generation, try a sieve of Eratosthenes, that's pretty fast. The rest looks okay
I have tried changing the Integer to Int but did not help much..
https://gist.github.com/c1ee2d6397cd5b28ade5
Thanks in advance. Sunil.