[Fwd: Re: [clean-list] Clean versus Haskell]

Simon Peyton-Jones simonpj at microsoft.com
Thu Oct 15 09:22:49 MEST 2009


I submitted Philippos as a performance bug to GHC's trac, here:
	http://hackage.haskell.org/trac/ghc/ticket/3586

If you follow the link you'll see lots of commentary, including a version that generates code twice as fast as Clean's, and is purely functional.

That said, I think it's v bad that a straightforward program runs so slowly, and it's certainly true that this is an area we could pay more attention to.  (Trouble is, there are so many such areas!)

Meanwhile, I'm curious: are the arrays in Philippos's program strict?  Or lazy?  If strict, that's a pretty big difference.  (The "STU" arrays mentioned in the above link are strict and unboxed; that's what the "U" means.)

Simon

| -----Original Message-----
| From: clean-list-bounces at science.ru.nl [mailto:clean-list-bounces at science.ru.nl] On
| Behalf Of Adrian Hey
| Sent: 15 October 2009 07:33
| To: clean-list at science.ru.nl
| Subject: [Fwd: Re: [clean-list] Clean versus Haskell]
| 
| 
| -------- Original Message --------
| Subject: Re: [clean-list] Clean versus Haskell
| Date: Thu, 15 Oct 2009 06:41:20 +0100
| From: Adrian Hey <ahey at iee.org>
| To: Philippos Apolinarius <phi500ac at yahoo.ca>
| References: <8400.82204.qm at web58803.mail.re1.yahoo.com>
| 
| Hello Philippos,
| 
| GHC has a long standing performance bug for garbage collection and
| mutable arrays:
| 
| http://hackage.haskell.org/trac/ghc/ticket/650
| 
| For some reason they haven't (can't?) fixed it. I guess the
| authors of Haskell/ghc shootout entries are aware of this so don't
| use native mutable arrays in their entries (at least not those that
| show haskell/ghc to be "fast" :-)
| 
| Regards
| --
| Adrian Hey
| 
| Philippos Apolinarius wrote:
| > I wrote a very simple program to check whether Haskell improved its array
| processing libraries or not. Here is how to compile and run the program arr.hs in
| Haskell (I have used the GHC compiler):
| >
| >> ghc -O arr.hs -o arr.exe
| >
| > $ time arr.exe +RTS -K32000000
| > 2.8e8
| >
| > real    0m3.938s
| > user    0m0.031s
| > sys     0m0.000s
| >
| > The same program in Clean:
| > C:\Clean 2.2\exemplos\console>arraytest.exe
| > 280000000
| > Execution: 0.01  Garbage collection: 0.01  Total: 0.03
| >
| > C:\Clean 2.2\exemplos\console>arraytest.exe
| > 280000000
| > Execution: 0.01  Garbage collection: 0.01  Total: 0.03
| >
| > This means that Clean is 390 times faster than Haskell in this particular problem.
| These results makes me worder whether Haskell is safer than Clean. It turns out that
| Haskell checks index out of range at runtime, exactly like Clean. Larger problems
| make the difference between Clean and Haskell even worse. For instance, neural
| networks like the one described in Schmidtt et al. run 400 times faster in Clean.
| >
| > Haskell seems to be slow, and not safe. For instance, GHC compiler does not at a
| program trying to write into a closed handle.
| >
| > module Main where
| >  import System( getArgs )
| >  import IO
| >
| >  main = do
| >           args <- getArgs
| >           if (length args /= 2)
| >         then putStr "Usage: f1a f2a <n>"
| >             else (do
| >               fromHandle <- openFile (head args)  ReadMode
| >               contents   <- hGetContents fromHandle
| >               toHandle <- openFile (head (tail args)) WriteMode
| >               hClose toHandle  -- Comment this line
| >               hPutStr toHandle contents
| >               hClose toHandle
| >               putStr "Done.")
| >
| > The Clean equivalent program is somewhat smaller. In my opinion it is easier to
| understand. What is more important, Clean compiler balks at closed handles.
| >
| > module cleancopy
| > import StdEnv, ArgEnv
| >
| > Start w
| >   # argv= getCommandLine
| >   | size argv < 3 = abort "Usage, etc."
| >   # (ok, f, w)= fopen argv.[1] FReadText w
| >       (contents, f)= freads f 64000
| >       (ok, f, w)= fopen argv.[2] FWriteText w
| >       f= fwrites contents f
| >   = fclose f w
| >
| > Below you will find the array examples. You can check that Clean is really much
| faster than Haskell. I wonder why the Benchmarks Game site does not report such a
| large difference between Haskell and Clean performances. I believe that people who
| wrote Haskell benchmarks for the Benchmarks Game site cheated in using foreign
| pointers to access arrays.
| >
| > -- arr.hs
| > import Control.Monad.ST
| > import Data.Array.ST
| > main = print $ runST
| >           (do arr <- newArray (1,2000000)
| >                         137.0 :: ST s
| >                                   (STArray s
| >                                     Int Double)
| >               a <- readArray arr 1
| >               b <- readArray arr 1
| >               fn 2000000 arr 0.0 )
| >
| >
| > fn i a acc | i < 1 = do (return acc)
| > fn i a acc= do
| >              b <- readArray a i
| >              writeArray a i (b+3.0)
| >              c <- readArray a i
| >              fn (i-1) a (acc+c)
| >
| > //Clean version
| > module arraytest
| > import StdEnv
| > fn i a acc | i<1 = acc
| > fn i a=:{[i]=b} acc
| >   # a= {a&[i]= b+3.0}
| >   # (c, a)= a![i]
| >   = fn (i-1) a (c+acc)
| >
| > Start= fn 2000000 vt 0.0
| > where
| >    vt:: .{#Real}
| >    vt = createArray 2000001 137.0



More information about the clean-list mailing list