[Haskell-cafe] slow code
Thomas ten Cate
ttencate at gmail.com
Mon Jun 15 03:15:32 EDT 2009
How much output does this generate? Does it matter if you send the
output to /dev/null? This looks as if the bottleneck might well be in
I/O operations, not in the code itself. To find this out, you could
rewrite the code in C and see if that makes a difference?
Thomas
On Sun, Jun 14, 2009 at 20:44, brian<briand at aracnet.com> wrote:
> Haskell Gurus,
>
> I have tried to use profiling to tell me what's going on here, but it hasn't
> helped much, probably because I'm not interpreting the results correctly.
>
> Empirically I have determined that the show's are pretty slow, so an
> alternative to them would be helpful. I replaced the show's with "", and
> compiled with -O2 and not much improvement.
>
> I need to write _a lot_ of code in this style. A few words about how best
> to do this would be helpful. Laziness, infinite lists, uvector ??
>
> Help...
>
> Thanks,
>
> Brian
>
>
> import Complex
> import System.IO
>
> genData :: Double -> Int -> (Double -> Complex Double) -> ([Double],
> [Complex Double])
> genData tstop n f =
> let deltat = tstop / (fromIntegral n)
> t = [ fromIntegral(i) * deltat | i <- [0..n-1]]
> in
> (t, map f t)
>
> main =
> do let (t, y) = genData 100.0E-6 (2 ^ 15) (\x -> x :+ 0.0)
> h <- openFile "data.txt" WriteMode
> mapM_ (\(x, y) ->
> do hPutStr h (show t)
> hPutStr h " "
> hPutStrLn h (show (realPart y)))
> (zip t y)
> hClose h
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list