[Haskell-cafe] Differences in optimisiation with interactive andcompiled mo

Branimir Maksimovic bmaxa at hotmail.com
Sun Dec 11 10:31:45 EST 2005




>From: Daniel Fischer <daniel.is.fischer at web.de>
>To: Bulat Ziganshin <bulatz at HotPOP.com>
>CC: Haskell-Cafe at haskell.org
>Subject: Re: [Haskell-cafe] Differences in optimisiation with interactive 
>andcompiled mo
>Date: Sun, 11 Dec 2005 14:59:55 +0100
>
>Am Samstag, 10. Dezember 2005 22:42 schrieb Bulat Ziganshin:
> > Hello Branimir,
> >
> > Saturday, December 10, 2005, 8:29:09 PM, you wrote:
> > >>Can you check this version?
> >
> > and this:
> >
> > replace from to = repl
> >   where repl s | Just remainder <- start_from from s  =  to ++ repl
> > remainder repl (c:cs)  =  c : repl cs
> >         repl [] = []
> >
> > start_from (x:xs) (y:ys) | x==y  =  start_from xs ys
> > start_from [] str                =  Just str
> > start_from _  _                  =  Nothing
>
>This is the fastest, even without type signatures (those give a wee bit of
>extra speed).

your test (unlikely in real scenario):

$ time replace1
Working very long
False
Done

real    0m12.531s
user    0m0.015s
sys     0m0.000s

my test is not any more 0.25 secs with your test, becasue I've sacrifised 
that
for my test speed :)

bmaxa at MAXA ~/tutorial
$ time searchr
Working very long
True
Done

real    0m4.000s
user    0m0.031s
sys     0m0.000s

my test:

bmaxa at MAXA ~/tutorial
$ ghc -fglasgow-exts  -O2 replace1.hs --make -o replace1.exe
Chasing modules from: replace1.hs
Compiling Main             ( replace1.hs, replace1.o )
Linking ...

bmaxa at MAXA ~/tutorial
$ ghc -fglasgow-exts  -O2 searchr.hs --make -o searchr.exe
Chasing modules from: searchr.hs
Compiling Main             ( searchr.hs, searchr.o )
Linking ...

bmaxa at MAXA ~/tutorial
$ time replace1
Working:seasearch replace  able seaseasearch baker seasearch charlie
True
Done


real    0m11.718s
user    0m0.015s
sys     0m0.015s

bmaxa at MAXA ~/tutorial
$ time searchr.exe
Working:seasearch replace  able seaseasearch baker seasearch charlie
True
Done


real    0m13.921s
user    0m0.015s
sys     0m0.015s

>Have you any idea why using a pattern guard is faster (not much, but
>consistently) than the equivalent case-expression?

Probably because either then function is better inlined, or there is
optimised tail recursion. In any way ghc very well optimises recursion.
I didn't notice any difference in speed whether function signature
is tagged only for strings or is polymorphic. So we can freely
make polymorphic signatures.

Greetings, Bane.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Haskell-Cafe mailing list