-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBenchmark.hs
61 lines (51 loc) · 1.77 KB
/
Benchmark.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{-# LANGUAGE RecordWildCards #-}
module Main where
import Criterion.Main
import Data.Either
import Control.Monad.Loops
import Bio.Motions.Prototype as Prototype
import System.Random
import Control.Monad.State.Strict
import Control.DeepSeq
import Control.Exception
import Control.Monad.Except
import Control.Monad.Random
globalParams :: Input
globalParams = Input
{ inputChainLength = 256
, inputLamins = [1, 8, 10, 23, 99]
, inputBinders = [7, 9, 11, 17, 63, 89]
, inputRadius = 30
, inputNumBinders = 20
}
generate :: MonadRandom m => Int -> Int -> [Atom] -> m SimulationState
generate radius numBinders chain = do
Right res <- iterateUntil isRight $ runExceptT $
genSimState radius numBinders chain space
return res
where
space = genSpace radius
runSim :: MonadRandom m => Int -> SimulationState -> m SimulationState
runSim steps st = flip execStateT st $ replicateM_ steps simulateStep
instance NFData SimulationState
instance NFData Atom
runBench :: ([Atom] -> SimulationState, [Atom])
-> (SimulationState -> SimulationState, SimulationState)
-> IO ()
runBench (gen, chain) (run, st) = defaultMain [
bgroup "pure" [
bench "genstate" $ nf gen chain,
bench "sim-100k" $ nf run st]
]
main :: IO ()
main = do
let Input{..} = globalParams
let stg = generate inputRadius inputNumBinders
chain <- evaluate $ force $ loadChain inputChainLength inputLamins inputBinders
chainRan <- newStdGen
let chainTest = (flip evalRand chainRan . stg, chain)
-- use different random generators for different tests
stateRan <- newStdGen
st <- evaluate . force =<< evalRandIO (stg chain)
let runTest = (flip evalRand stateRan . runSim (10^5), st)
runBench chainTest runTest