haskell-numerics / random-fu

A suite of Haskell libraries for representing, manipulating, and sampling random variables
42 stars 21 forks source link

Why sampleState much faster than runRVar? #38

Open mvoidex opened 7 years ago

mvoidex commented 7 years ago

Why

sampleState (replicateM 1000000 stdNormal :: RVar [Double]) g

much faster (<1 src vs ~20 secs) than

runRVar (replicateM 1000000 stdNormal :: RVar [Double]) StdRandom

?

idontgetoutmuch commented 7 years ago

Interesting. It would take some investigation. Maybe you could post a full program? I don't think sampling 1e6 normals should take even a second but maybe my intuition is incorrect.

mvoidex commented 7 years ago

Here

module Main where

import Control.Monad
import Control.DeepSeq
import Data.Random
import System.Random

main :: IO ()
main = do
    -- dbls <- (fst . sampleState (replicateM 1000000 stdNormal :: RVar [Double])) <$> newStdGen
    dbls <- runRVar (replicateM 1000000 stdNormal :: RVar [Double]) StdRandom
    dbls `deepseq` print (length dbls)

Results: ~1.5 secs vs ~20