mischief-ecs-0.2.0.0: benchmarks/bench-update.hs
module Main where
import Control.DeepSeq (NFData (rnf))
import Control.Monad (replicateM_)
import Criterion.Main
import Criterion.Types
import Data.Foldable
import Mischief.ECS
main :: IO ()
main =
defaultMainWith
defaultConfig {reportFile = Just "/home/pvd/mischief/benches/update.html"}
[ benchEntities 10,
benchEntities 100,
benchEntities 1000,
benchEntities 10000
]
benchEntities :: Int -> Benchmark
benchEntities a = bgroup (show a ++ " Entities") $ [env (mkWorld a) $ benchUpdates a b | b <- [1]]
benchUpdates :: Int -> Int -> W -> Benchmark
benchUpdates a b w = bench (show b ++ " Updates") $ nfIO $ benchUpdate a b w
benchUpdate :: Int -> Int -> W -> IO ()
benchUpdate _ b (W w) = replicateM_ b (runSystem up w)
data Comp1 = Comp1 deriving (Component)
newtype W = W World
instance NFData W where
rnf _ = ()
mkWorld :: Int -> IO W
mkWorld n = do
app <- newApp
runSystem (pre n) app.world
pure $ W app.world
pre :: Int -> System ()
pre m = replicateM_ m (spawn Comp1)
up :: System ()
up = do
[q|Comp1|]
& qinsert (const Comp1)
& query_