From 6d2c03b2772989e0808dfaabb1b9ceeb9f2cdda8 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 14 Jan 2025 23:31:56 +0300 Subject: [PATCH 1/2] Drop betaBinomial* benchmarks Just use plain beta ones. betaBinomialTable does something horrible - constructing CT for each call. This makes running benchmark slow for no gain --- bench/Benchmark.hs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/bench/Benchmark.hs b/bench/Benchmark.hs index c759ba9..2e2aa19 100644 --- a/bench/Benchmark.hs +++ b/bench/Benchmark.hs @@ -93,6 +93,7 @@ main = do , bench "exponential" $ whnfIO $ loop iter (exponential 3 mwc :: IO Double) , bench "gamma,a<1" $ whnfIO $ loop iter (gamma 0.5 1 mwc :: IO Double) , bench "gamma,a>1" $ whnfIO $ loop iter (gamma 2 1 mwc :: IO Double) + , bench "beta" $ whnfIO $ loop iter (beta 2 3 mwc :: IO Double) , bench "chiSquare" $ whnfIO $ loop iter (chiSquare 4 mwc :: IO Double) -- NOTE: We switch between algorithms when Np=10 , bgroup "binomial" @@ -106,10 +107,6 @@ main = do , (6000, 0.2), (6000, 0.8) ] ] - , 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 @@ -158,13 +155,3 @@ main = do ] #endif ] - -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 From 9973b53b45a080317f9f07345093001e3752451d Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 14 Jan 2025 22:23:41 +0300 Subject: [PATCH 2/2] Add -O2 It gives good speedup for construction of condensed tables and methods of new SeedGen. Performance of everything else stays same. I think it's worthwhile change --- mwc-random.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mwc-random.cabal b/mwc-random.cabal index f647fff..68f8c68 100644 --- a/mwc-random.cabal +++ b/mwc-random.cabal @@ -74,7 +74,7 @@ library , vector >= 0.7 , math-functions >= 0.2.1.0 - ghc-options: -Wall -funbox-strict-fields -fwarn-tabs + ghc-options: -O2 -Wall -funbox-strict-fields -fwarn-tabs -- We want to be able to build benchmarks using both tasty-bench and tasty-papi.