[Haskell-cafe] Performance problem with random numbers
Don Stewart
dons at galois.com
Sat Oct 13 17:37:39 EDT 2007
isaacdupree:
> 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.)
>
I've seen similar results switching to the SIMD mersenne twister C
implementation for randoms:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html
If there's interest, I can package up the bindings for hackage.
-- Don
More information about the Haskell-Cafe
mailing list