Faster, GHC, and floating point.
Simon Marlow
simonmar at microsoft.com
Mon Oct 20 18:18:19 EDT 2003
> using -fexcess-precision improves the runtime from about 180259 ns to
> 140201 ns on my environment (Intel P3, 700Mhz, 384 MB Ram, Win2k).
> That makes for me a speedup of 1.29. I tested the other flags,
> -funbox-strict-fields -fliberate-case-threshold100 but did not see an
> improvement.
> Well, pure Haskell has a runtime of
>
> 140201 ns
>
> as stated above for a test of 9000 calls (thanks to the "sum $ map f
> [inputlist]" pattern!). If i use the C aibd as foreign call, i get a
> runtime of
>
> 80115 ns
>
> That's pretty good (both ghc6.0.1 on MinGW windows env). But
> if i look at
> my Java or C++ solution, then Java takes for the same task
> (JVM 1.4.2_01
> client vm)
>
> 30000 ns.
Looking at your code, it looks like you should add some more strictness.
eg:
sekantenVerfahren :: Funktion -> Genauigkeit -> Genauigkeit -> Int ->
Double -> Double
sekantenVerfahren f gx gy tiefe start = sekantenIter f tiefe gx gy x1 x2
y1
y2 where
x1 = start
x2 = start + start * 0.1
y1 = f x1
y2 = f x2
sekantenIter _ 0 _ _ _ x2 _ _ = x2
sekantenIter f tiefe gx gy x1 x2 y1 y2 =
let
x3 = x2 - y2 * (x2 - x1) / (y2 - y1)
y3 = f x3
dy = y3 - y2
dx = x3 - x2
in
if (istOk gx x3 dx) && (istOk gy y3 dy) then x3
else sekantenIter f (tiefe-1) gx gy x2 x3 y2 y3
Some of the parameters to the inner recursive function 'sekantenIter'
are lazy. Try adding some seqs to help the strictness analyser:
sekantenIter _ 0 _ _ _ x2 _ _ = x2
sekantenIter f tiefe gx gy x1 x2 y1 y2 =
let
x3 = x2 - y2 * (x2 - x1) / (y2 - y1)
y3 = f x3
dy = y3 - y2
dx = x3 - x2
in
x3 `seq` y3 `seq` dy `seq` dx `seq`
if (istOk gx x3 dx) && (istOk gy y3 dy) then x3
else sekantenIter f (tiefe-1) gx gy x2 x3 y2 y3
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list