Here is a quick fix for the Random Numbers category.  Looks like a
classic space-leak, again on the arithmetic operations.  Speeds up
results for me about 6X and brings memory usage down out of the
stratosphere.

w/o strictness:

~/shootout$ time random 900000 +RTS -K32000000
75.544410151

real    0m0.756s
user    0m0.670s
sys     0m0.050s



w/ strictness:

~/shootout$ time random 900000 # <-- don't need massive heap
75.544410151

real    0m0.139s
user    0m0.100s
sys     0m0.010s

-- 
  Robert
  [EMAIL PROTECTED]

--- random.ghc	2004-10-07 08:51:20.000000000 -0400
+++ random.hs	2004-10-07 08:52:27.000000000 -0400
@@ -12,7 +12,9 @@
 
 randloop :: Int -> Int -> Double -> Double -> Double
 randloop 0 seed r max = r
-randloop n seed r max = randloop (n-1) newseed newrand max
+randloop n seed r max
+	| n `seq` seed `seq` r `seq` False = undefined
+	| otherwise =  randloop (n-1) newseed newrand max
     where normalize x max = (fromIntegral x) * (max / imd)
           newseed         = (seed * ia + ic) `mod` im
           newrand         = normalize newseed max
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to