[Haskell-beginners] Performance of Idiomatic lazy Haskell

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


1. I used Your lualoop file with content:
module Main (main) where

main :: IO ()
main = do
   --putStrLn "EPS:"
   -- eps <- readLn :: IO Double
   print $ 4*calcPi 0.00000001

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

2.
F:\MeineUebungen>ghc -O2 -fforce-recomp -fexcess-precision -fvia-C -optc-O3 -o c
loop --make p085-pi_lualoop.hs
[1 of 1] Compiling Main             ( p085-pi_lualoop.hs, p085-pi_lualoop.o )
Linking cloop.exe ...


F:\MeineUebungen>ghc -O2 -fforce-recomp -o nloop --make p085-pi_lualoop.hs
[1 of 1] Compiling Main             ( p085-pi_lualoop.hs, p085-pi_lualoop.o )
Linking nloop.exe ...

F:\MeineUebungen>cloop +RTS -sstderr
cloop +RTS -sstderr
3.1415926485894725
          20,860 bytes allocated in the heap
             892 bytes copied during GC
           3,068 bytes maximum residency (1 sample(s))
          13,316 bytes maximum slop
               1 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:     0 collections,     0 parallel,  0.00s,  0.00s elapsed
  Generation 1:     1 collections,     0 parallel,  0.00s,  0.00s elapsed

  INIT  time    0.02s  (  0.02s elapsed)
  MUT   time    7.39s  (  7.27s elapsed)
  GC    time    0.00s  (  0.00s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    7.41s  (  7.28s elapsed)

  %GC time       0.0%  (0.0% elapsed)

  Alloc rate    2,816 bytes per MUT second

  Productivity  99.8% of total user, 101.5% of total elapsed


F:\MeineUebungen>nloop +RTS -sstderr
nloop +RTS -sstderr
3.1415926485894725
          20,860 bytes allocated in the heap
             892 bytes copied during GC
           3,068 bytes maximum residency (1 sample(s))
          13,316 bytes maximum slop
               1 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:     0 collections,     0 parallel,  0.00s,  0.00s elapsed
  Generation 1:     1 collections,     0 parallel,  0.00s,  0.00s elapsed

  INIT  time    0.02s  (  0.00s elapsed)
  MUT   time    4.77s  (  4.81s elapsed)
  GC    time    0.00s  (  0.00s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    4.78s  (  4.81s elapsed)

  %GC time       0.0%  (0.0% elapsed)

  Alloc rate    4,362 bytes per MUT second

  Productivity  99.7% of total user, 99.0% of total elapsed


-- Markus



On Mon, Feb 1, 2010 at 3:40 PM, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> Am Montag 01 Februar 2010 15:22:45 schrieb Markus Böhm:
>
>> Daniel, I use GHC 6.12.1 and Windows XP.
>
> *sigh*
>
> Have you a CygWin installed? It should run as given from a CygWin shell, I
> believe.
>
>> The time command doesn't seem
>> to work. It says in German: specified time can't be read. Give a new
>> time.
>
> Replace "time" with however you get the CPU time used by a process on
> Windows.
> But I think Windows doesn't allow piping, and I'm not sure whether it has
> echo, so see below.
>
>> Daniel, here another feedback:
>>
>> F:\MeineUebungen>ghc -O2 -fexcess-precision -fvia-C -optc-O3 -o luaLoop
>> --make p 085-pi_lualoop.hs
>> [1 of 1] Compiling Main             ( p085-pi_lualoop.hs,
>> p085-pi_lualoop.o ) Linking luaLoop.exe ...
>>
>> F:\MeineUebungen>echo '0.00000001' | time ./luaLoop
>> Eingegebene Zeit kann nicht übernommen werden.
>> Geben Sie die neue Zeit ein:
>>
>> F:\MeineUebungen>luaLoop +RTS -sstderr -RTS
>> luaLoop +RTS -sstderr
>> EPS:
>> 0.00000001
>> 3.1415926485894725
>>           61,428 bytes allocated in the heap
>>            1,316 bytes copied during GC
>>            4,564 bytes maximum residency (1 sample(s))
>>           11,820 bytes maximum slop
>>                1 MB total memory in use (0 MB lost due to fragmentation)
>>
>>   Generation 0:     0 collections,     0 parallel,  0.00s,  0.00s
>> elapsed Generation 1:     1 collections,     0 parallel,  0.00s,  0.00s
>> elapsed
>>
>>   INIT  time    0.02s  (  0.00s elapsed)
>>   MUT   time    8.06s  ( 16.83s elapsed)
>>   GC    time    0.00s  (  0.00s elapsed)
>>   EXIT  time    0.00s  (  0.00s elapsed)
>>   Total time    8.08s  ( 16.83s elapsed)
>>
>>   %GC time       0.0%  (0.0% elapsed)
>>
>>   Alloc rate    7,604 bytes per MUT second
>>
>>   Productivity  99.8% of total user, 47.9% of total elapsed
>
> What?????
>
> Please try the following:
>
> 1) hardcode eps = 1e-8 in the source (or get it via getArgs and pass it as
> a command line argument)
> 2) ghc -O2 -fforce-recomp -fexcess-precision -fvia-C -optc-O3 -o cloop --
> make Source.hs
> 3) ghc -O2 -fforce-recomp -o nloop --make Source.hs
> 4) cloop +RTS -sstderr
> 5) nloop +RTS -sstderr
>
>>
>> -- Markus
>>
>


More information about the Beginners mailing list