Skip to content

Commit 742f8ff

Browse files
committed
feat: minibench -> add
1 parent e46daf7 commit 742f8ff

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

bench/Data/Array.purs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Bench.Data.Array where
2+
3+
import Prelude
4+
5+
import Data.Array as Array
6+
import Data.Maybe (Maybe(..))
7+
import Effect (Effect)
8+
import Effect.Console (log)
9+
import Performance.Minibench (benchWith)
10+
11+
benchArray :: Effect Unit
12+
benchArray = do
13+
log "mapMaybe"
14+
log "---------------"
15+
benchMapMaybe
16+
17+
where
18+
19+
benchMapMaybe = do
20+
let shortNats = Array.range 0 100
21+
longNats = Array.range 0 10000
22+
onlyEven x = if x `mod` 2 == 0 then Just x else Nothing
23+
24+
log $ "mapMaybe (" <> show (Array.length shortNats) <> ")"
25+
benchWith 1000 \_ -> Array.mapMaybe onlyEven shortNats
26+
27+
log $ "mapMaybe (" <> show (Array.length longNats) <> ")"
28+
benchWith 100 \_ -> Array.mapMaybe onlyEven longNats

bench/Main.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Bench.Main where
2+
3+
import Prelude
4+
5+
import Bench.Data.Array (benchArray)
6+
import Effect (Effect)
7+
import Effect.Console (log)
8+
9+
main :: Effect Unit
10+
main = do
11+
log "Array"
12+
log "==="
13+
benchArray

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"purescript-unsafe-coerce": "^4.0.0"
3030
},
3131
"devDependencies": {
32+
"purescript-minibench": "^2.0.0",
3233
"purescript-assert": "^4.0.0",
3334
"purescript-console": "^4.0.0",
3435
"purescript-const": "^4.0.0"

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "eslint src && pulp build -- --censor-lib --strict",
6-
"test": "pulp test"
6+
"test": "pulp test",
7+
"bench:build": "pulp build --include bench -- --censor-lib --strict",
8+
"bench:run": "node --expose-gc -e \"require('./output/Bench.Main/index.js').main()\"",
9+
"bench": "npm run bench:build && npm run bench:run"
710
},
811
"devDependencies": {
912
"eslint": "^4.19.1",

0 commit comments

Comments
 (0)