Skip to content

feat: minibench -> add #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions bench/Data/Array.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Bench.Data.Array where

import Prelude

import Data.Array as Array
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Console (log)
import Performance.Minibench (benchWith)

benchArray :: Effect Unit
benchArray = do
log "mapMaybe"
log "---------------"
benchMapMaybe

where

benchMapMaybe = do
let shortNats = Array.range 0 100
longNats = Array.range 0 10000
onlyEven x = if x `mod` 2 == 0 then Just x else Nothing

log $ "mapMaybe (" <> show (Array.length shortNats) <> ")"
benchWith 1000 \_ -> Array.mapMaybe onlyEven shortNats

log $ "mapMaybe (" <> show (Array.length longNats) <> ")"
benchWith 100 \_ -> Array.mapMaybe onlyEven longNats
13 changes: 13 additions & 0 deletions bench/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Bench.Main where

import Prelude

import Bench.Data.Array (benchArray)
import Effect (Effect)
import Effect.Console (log)

main :: Effect Unit
main = do
log "Array"
log "==="
benchArray
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"purescript-unsafe-coerce": "master"
},
"devDependencies": {
"purescript-minibench": "master",
"purescript-assert": "master",
"purescript-console": "master",
"purescript-const": "master"
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test"
"test": "pulp test",
"bench:build": "pulp build --include bench -- --censor-lib --strict",
"bench:run": "node --expose-gc -e \"require('./output/Bench.Main/index.js').main()\"",
"bench": "npm run bench:build && npm run bench:run"
},
"devDependencies": {
"eslint": "^4.19.1",
Expand Down