[Haskell-cafe] Performance problem with random numbers

Isaac Dupree isaacdupree at charter.net
Sat Oct 13 17:33:41 EDT 2007


ntupel wrote:
> Thanks for your reply Stefan. Unfortunately I could measure only a
> relatively small improvement by changing to concrete types

> the sample code was about one second faster when compiled with -O2.
> Profiling again indicated that most time was spend in random and randomR

GHC StdGen's random and randomR are somewhat slow.  I found that 
changing to a custom ((x*a + b) `mod` c) random-generator (instance of 
RandomGen) much sped things up (since nothing depended on the random 
numbers being good quality).  (Then I switched to a small C function to 
do the randomization and make all the OpenGL calls, and it sped up by 
another factor of 4.)

Isaac


More information about the Haskell-Cafe mailing list