Fwd: [Haskell-cafe] Optimization fun

Gah! Gmail has really broken defaults for posting to lists.
On 10/02/07, Creighton Hogg
Hello Haskell-ers, So a friend and I were thinking about making code faster in Haskell, and I was wondering if there was a way to improve the following method of generating the list of all prime numbers. It takes about 13 seconds to run, meanwhile my friend's C version took 0.1. I'd love to learn a bit more about how to optimize Haskell code.
Which subproblem takes 13 seconds? (Surely generating a list of all
primes will take an infinite amount of time, since there are
infinitely many of them?)
--
Peter Berry

On 2/10/07, Peter Berry
Gah! Gmail has really broken defaults for posting to lists.
On 10/02/07, Creighton Hogg
wrote: Hello Haskell-ers, So a friend and I were thinking about making code faster in Haskell, and I was wondering if there was a way to improve the following method of generating the list of all prime numbers. It takes about 13 seconds to run, meanwhile my friend's C version took 0.1. I'd love to learn a bit more about how to optimize Haskell code.
Which subproblem takes 13 seconds? (Surely generating a list of all primes will take an infinite amount of time, since there are infinitely many of them?)
Apparently I shouldn't send e-mails quickly, as it comes out as gibberish. It was the first 10000. The thirteen seconds was just approximate, but it showed the C one was much faster, which I figured was because I had constructed it poorly. Apparently I had, and I even managed to type it in wrong.

Yeah, the 10000 first primes takes about 0.1 seconds in Haskell too using the code I posted. On Feb 10, 2007, at 21:49 , Creighton Hogg wrote:
On 2/10/07, Peter Berry
wrote: Gah! Gmail has really broken defaults for posting to lists. On 10/02/07, Creighton Hogg
wrote: Hello Haskell-ers, So a friend and I were thinking about making code faster in Haskell, and I was wondering if there was a way to improve the following method of generating the list of all prime numbers. It takes about 13 seconds to run, meanwhile my friend's C version took 0.1. I'd love to learn a bit more about how to optimize Haskell code.
Which subproblem takes 13 seconds? (Surely generating a list of all primes will take an infinite amount of time, since there are infinitely many of them?)
Apparently I shouldn't send e-mails quickly, as it comes out as gibberish. It was the first 10000. The thirteen seconds was just approximate, but it showed the C one was much faster, which I figured was because I had constructed it poorly. Apparently I had, and I even managed to type it in wrong.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Creighton Hogg
-
Lennart Augustsson
-
Peter Berry