[Haskell-beginners] Performance of Idiomatic lazy Haskell

Markus Böhm markus.boehm at googlemail.com
Mon Feb 1 09:08:58 EST 2010


Daniel, I use GHC 6.12.1 and Windows XP. The time command doesn't seem
to work. It says in German: specified time can't be read. Give a new
time.

-- Markus




On Mon, Feb 1, 2010 at 2:52 PM, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> Am Montag 01 Februar 2010 14:31:40 schrieb Markus Böhm:
>> Daniel, with LuaJIT it needs 1.45 sec cpu-time on my machine with
>> attached variant.
>
> That's pretty fast.
>
>> I compiled all our Haskell variants with ghc --make -O2.
>
> Well, GHC isn't as good at loop-optimising as gcc is. Depending on the
> loop, the via-C compiled binaries are between 1.4 and 2.3 times faster than
> the NCG compiled.
>
>> I don't know about -fvia-C, have to find out. I hope I didn't
>> distract You with my Lua variant.
>
> No sweat.
>
>> In any case thank You very much for
>> your advice. Markus.
>>
>
> You're welcome.
>
> Can you try the below with
>
> ghc -O2 -fexcess-precision -fvia-C -optc-O3 -o luaLoop --make Whatever.hs
>
> and run with
>
> echo '0.00000001' | time ./luaLoop
>
> ?
> It's a fairly direct translation of the Lua code, and it runs here more or
> less equally fast as (gcc compiled) C-loops.
>
> =================================
> module Main (main) where
>
> main :: IO ()
> main = do
>    putStrLn "EPS:"
>    eps <- readLn :: IO Double
>    print $ 4*calcPi eps
>
> calcPi :: Double -> Double
> calcPi eps = go False 1 3
>      where
>        go bl p1 i
>            | 4*abs(p2-p1) < eps    = p1
>            | otherwise             = go (not bl) p2 (i+2)
>              where
>                p2  | bl        = p1+1/i
>                    | otherwise = p1-1/i
>
> ==================================
>
>


More information about the Beginners mailing list