Skip to content

Commit b6969db

Browse files
committed
Make benchmar more fair
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
1 parent fdf9d6e commit b6969db

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

bench/Bench/Main.purs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ testBindLeft n' = do
5353

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

84+
timed :: Array String -> Ef BenchEff Unit -> Eff BenchEff Unit
85+
timed msg ef = do
86+
let eff = liftEf ef
87+
logBench' msg $ benchWith' 5 \_ -> unsafePerformEff eff
88+
8289
header :: String
8390
header =
8491
"| bench | type | n | mean | stddev | min | max |\n" <>
@@ -97,8 +104,8 @@ bench3 name buildEff buildEf buildAff vals = for_ vals \val -> do
97104
logBench' [name <> " build", "Ef", show val] $ benchWith' 1000 \_ -> buildEf val
98105
let eff = liftEff $ buildEff val
99106
logBench [name <> " run", "Eff", show val] $ benchWith' 1000 \_ -> unsafePerformEff eff
100-
let aff = buildAff val
101-
logBench [name <> " run", "Aff", show val] $ benchWith' 1000 \_ -> unsafePerformEff $ launchAff_ aff
107+
let aff = launchAff_ $ buildAff val
108+
logBench [name <> " run", "Aff", show val] $ benchWith' 1000 \_ -> unsafePerformEff aff
102109
let ef = liftEf $ buildEf val
103110
logBench' [name <> " run", "Ef", show val] $ benchWith' 1000 \_ -> unsafePerformEff ef
104111

@@ -111,8 +118,8 @@ bench2
111118
bench2 name buildEf buildAff vals = for_ vals \val -> do
112119
logBench [name <> " build", "Aff", show val] $ benchWith' 4 \_ -> buildAff val
113120
logBench' [name <> " build", "Ef", show val] $ benchWith' 4 \_ -> buildEf val
114-
let aff = buildAff val
115-
logBench [name <> " run", "Aff", show val] $ benchWith' 4 \_ -> unsafePerformEff $ launchAff_ aff
121+
let aff = launchAff_ $ buildAff val
122+
logBench [name <> " run", "Aff", show val] $ benchWith' 4 \_ -> unsafePerformEff aff
116123
let ef = liftEf $ buildEf val
117124
logBench' [name <> " run", "Ef", show val] $ benchWith' 4 \_ -> unsafePerformEff ef
118125

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'",
88
"bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'",
99
"bench:run:extended": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").extended()'",
10+
"bench:all": "npm run bench:build && npm run bench:run && npm run bench:run:extended",
1011
"bench": "npm run bench:build && npm run bench:run"
1112
},
1213
"devDependencies": {

0 commit comments

Comments
 (0)