Skip to content

Commit

Permalink
Benchmark a "realistic" usage of binomial
Browse files Browse the repository at this point in the history
  • Loading branch information
idontgetoutmuch committed Jun 12, 2024
1 parent 4ebd207 commit 118b1b1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bench/Benchmark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Data.Word
import Data.Proxy
import qualified Data.Vector.Unboxed as U
import qualified System.Random as R
import System.Random.Stateful (StatefulGen)
import System.Random.MWC
import System.Random.MWC.Distributions
import System.Random.MWC.CondensedTable
Expand Down Expand Up @@ -92,6 +93,10 @@ main = do
, bench "gamma,a>1" $ whnfIO $ loop iter (gamma 2 1 mwc :: IO Double)
, bench "chiSquare" $ whnfIO $ loop iter (chiSquare 4 mwc :: IO Double)
, bench "binomial" $ whnfIO $ loop iter (binomial 1400 0.4 mwc :: IO Int)
, bench "beta binomial 10" $ whnfIO $ loop iter (betaBinomial 600 400 10 mwc :: IO Int)
, bench "beta binomial 100" $ whnfIO $ loop iter (betaBinomial 600 400 100 mwc :: IO Int)
, bench "beta binomial table 10" $ whnfIO $ loop iter (betaBinomialTable 600 400 10 mwc :: IO Int)
, bench "beta binomial table 100" $ whnfIO $ loop iter (betaBinomialTable 600 400 100 mwc :: IO Int)
]
-- Test sampling performance. Table creation must be floated out!
, bgroup "CT/gen" $ concat
Expand Down Expand Up @@ -133,3 +138,13 @@ main = do
, bench "Int" $ whnfIO $ loop iter (M.random mtg :: IO Int)
]
]

betaBinomial :: StatefulGen g m => Double -> Double -> Int -> g -> m Int
betaBinomial a b n g = do
p <- beta a b g
binomial n p g

betaBinomialTable :: StatefulGen g m => Double -> Double -> Int -> g -> m Int
betaBinomialTable a b n g = do
p <- beta a b g
genFromTable (tableBinomial n p) g

0 comments on commit 118b1b1

Please sign in to comment.