
Hello,
I was thinking about using haskell to do some 'realtime' audio signal
processing, and am trying to figure out how close to the holy grail of
"C" code I can get when it comes to speed. Currently, it looks like I
might be looking at running 10 times slower. Is there stuff I could do
to get better performance out of haskell?
In example 1, I create an unitialized 1.8MB array of type 'IOUArray
Int Word8', and write it to a file. This takes a mere 0.056 seconds
(on an Athlon 600).
module Main where
import Data.Array
import Data.Array.IO
import System.IO
main = do h <- openBinaryFile "test.b" WriteMode
a <- newArray_ (1,1800000)
hPutArray h a 1800000
In example 2, I apply a filter to the array (in this case, the filter
is just the id function). This takes around 1.06 seconds.
main = do h <- openBinaryFile "test.b" WriteMode
a <- newArray_ (1,1800000)
b <- mapArray id a
hPutArray h b 1800000
If I apply the 'filter' twice, the time increases to 2.58 seconds:
main = do h <- openBinaryFile "test.b" WriteMode
a <- newArray_ (1,1800000)
b <- mapArray id a
c <- mapArray id b
hPutArray h c 1800000
By comparison, the following c program runs in 0.10 seconds:
#include

Hmmm. With -O2 on GHC 6.2, I get 0.177s, 0.217s, and 0.348s for your three Haskell examples and 0.187s (with gcc -O2) for your C example. The output of -ddump-simpl for the looks perfect for the second Haskell example. My GHC seems to be doing a bang-up job here. What's wrong with yours? (For the third example GHC's code could be improved by additional inlining or hoisting of a constant array outside of the loop.) mike

Hrm, I am going to do some new test tonight. I think my test environment may have been bad... Jeremy Shaw. At Mon, 23 Feb 2004 13:37:45 -0800, Mike Gunter wrote:
Hmmm. With -O2 on GHC 6.2, I get 0.177s, 0.217s, and 0.348s for your three Haskell examples and 0.187s (with gcc -O2) for your C example. The output of -ddump-simpl for the looks perfect for the second Haskell example. My GHC seems to be doing a bang-up job here. What's wrong with yours? (For the third example GHC's code could be improved by additional inlining or hoisting of a constant array outside of the loop.)
mike

Hrm, Okay, it seems that my problems maybe be due to using ghc 6.3. Here are the results of running test under different compiler versions (see end of message for code): Athlon 600MHz + FreeBSD + GHC 6.0.1 real 0m0.414s user 0m0.361s sys 0m0.016s Athlon 600MHz + FreeBSD + GHC 6.3 (built from CVS HEAD on Feb 15, 2004) real 0m2.517s user 0m2.289s sys 0m0.069s Pentium III 1.13GHz + Debian + GHC 6.2 real 0m0.305s user 0m0.196s sys 0m0.027s Pentium III 1.13GHz + Debian + GHC 6.3 (built from CVS HEAD on Feb 1, 2004) real 0m1.302s user 0m1.196s sys 0m0.044s So it seems like maybe GHC 6.3's performance for this particular test is around 3-5 slower? Jeremy Shaw. module Main where import Data.Array import Data.Array.IO import System.IO main = do h <- openFile "test.b" WriteMode a <- newArray_ (1,1800000) b <- mapArray id a c <- mapArray id b hPutArray h c 1800000 At Mon, 23 Feb 2004 13:37:45 -0800, Mike Gunter wrote:
Hmmm. With -O2 on GHC 6.2, I get 0.177s, 0.217s, and 0.348s for your three Haskell examples and 0.187s (with gcc -O2) for your C example. The output of -ddump-simpl for the looks perfect for the second Haskell example. My GHC seems to be doing a bang-up job here. What's wrong with yours? (For the third example GHC's code could be improved by additional inlining or hoisting of a constant array outside of the loop.)
mike
participants (2)
-
Jeremy Shaw
-
Mike Gunter