[Haskell-cafe] newbie optimization question

Ryan Dickie goalieca at gmail.com
Sun Oct 28 16:00:16 EDT 2007


One thing I've noticed is that turning on optimizations significantly
increases the speed of haskell code. Are you comparing code between
languages with -O2 or without opts?

On 10/28/07, Prabhakar Ragde <plragde at uwaterloo.ca> wrote:
>
> For the purposes of learning, I am trying to optimize some variation of
> the following code for computing all perfect numbers less than 10000.
>
> divisors i = [j | j<-[1..i-1], i `mod` j == 0]
> main = print [i | i<-[1..10000], i == sum (divisors i)]
>
> I know this is mathematically stupid, but the point is to do a moderate
> nested-loops computation. On my 2.33GHz dual-core MacBookPro, the
> obvious C program takes about .3 seconds, and a compiled OCaML program
> (tail recursion, no lists) about .33 seconds. The above takes about 4
> seconds.
>
> I've tried using foldl', and doing explicit tail recursion with strict
> accumulators, but I can't get the running time below 3 seconds. Is it
> possible to come within striking distance of the other languages?
> Thanks. --PR
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071028/4c6929ee/attachment-0001.htm


More information about the Haskell-Cafe mailing list