Skip to content

Commit

Permalink
Make benchmar more fair
Browse files Browse the repository at this point in the history
Mapping was happening on pure node, such operation was optimised explicitly in Aff, so switched to do map on effect so it's more fair
  • Loading branch information
safareli committed Dec 13, 2017
1 parent fdf9d6e commit b6969db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions bench/Bench/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ testBindLeft n' = do

testMap :: forall m. MonadEff BenchEff m => Int -> m Unit
testMap n = do
res <- mapLoop n (pure 0)
arr <- liftEff mkArr
res <- mapLoop n (liftEff $ pushToArr arr 0)
pure unit
where
mapLoop :: Monad m => Int -> m Int -> m Int
Expand All @@ -76,9 +77,15 @@ extended = do
log header
bench2 ">>=R" testBindRight testBindRight [20000, 50000, 100000, 1000000]
bench2 ">>=L" testBindLeft testBindLeft [20000, 50000, 100000, 1000000]
bench2 "map" testMap testMap [10000, 20000, 50000, 100000, 1000000, 10000000]
bench2 "map" testMap testMap [10000, 20000, 50000, 100000, 1000000]
timed ["map", "Ef", "10000000"] $ testMap 10000000 -- Aff can't handle this number I got- JavaScript heap out of memory
bench2 "apply" testApply testApply [10000, 20000, 50000, 100000, 1000000]

timed :: Array String -> Ef BenchEff Unit -> Eff BenchEff Unit
timed msg ef = do
let eff = liftEf ef
logBench' msg $ benchWith' 5 \_ -> unsafePerformEff eff

header :: String
header =
"| bench | type | n | mean | stddev | min | max |\n" <>
Expand All @@ -97,8 +104,8 @@ bench3 name buildEff buildEf buildAff vals = for_ vals \val -> do
logBench' [name <> " build", "Ef", show val] $ benchWith' 1000 \_ -> buildEf val
let eff = liftEff $ buildEff val
logBench [name <> " run", "Eff", show val] $ benchWith' 1000 \_ -> unsafePerformEff eff
let aff = buildAff val
logBench [name <> " run", "Aff", show val] $ benchWith' 1000 \_ -> unsafePerformEff $ launchAff_ aff
let aff = launchAff_ $ buildAff val
logBench [name <> " run", "Aff", show val] $ benchWith' 1000 \_ -> unsafePerformEff aff
let ef = liftEf $ buildEf val
logBench' [name <> " run", "Ef", show val] $ benchWith' 1000 \_ -> unsafePerformEff ef

Expand All @@ -111,8 +118,8 @@ bench2
bench2 name buildEf buildAff vals = for_ vals \val -> do
logBench [name <> " build", "Aff", show val] $ benchWith' 4 \_ -> buildAff val
logBench' [name <> " build", "Ef", show val] $ benchWith' 4 \_ -> buildEf val
let aff = buildAff val
logBench [name <> " run", "Aff", show val] $ benchWith' 4 \_ -> unsafePerformEff $ launchAff_ aff
let aff = launchAff_ $ buildAff val
logBench [name <> " run", "Aff", show val] $ benchWith' 4 \_ -> unsafePerformEff aff
let ef = liftEf $ buildEf val
logBench' [name <> " run", "Ef", show val] $ benchWith' 4 \_ -> unsafePerformEff ef

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'",
"bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'",
"bench:run:extended": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").extended()'",
"bench:all": "npm run bench:build && npm run bench:run && npm run bench:run:extended",
"bench": "npm run bench:build && npm run bench:run"
},
"devDependencies": {
Expand Down

0 comments on commit b6969db

Please sign in to comment.