Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/.psc*
/.purs*
/.psa*
package-lock.json
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ language: node_js
dist: trusty
sudo: required
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
- bower install
- bower install --production
script:
- npm run -s build
- bower install
- npm run -s test
after_success:
- >-
test $TRAVIS_TAG &&
echo $GITHUB_TOKEN | pulp login &&
echo y | pulp publish --no-push
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "pulp build -- --censor-lib --strict"
"build": "pulp build -- --censor-lib --strict",
"test": "pulp test"
},
"devDependencies": {
"pulp": "^12.2.0",
Expand Down
38 changes: 33 additions & 5 deletions src/Performance/Minibench.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
module Performance.Minibench
( bench
, benchWith
, benchWith'
, BenchResult
, withUnits
) where

import Prelude hiding (min,max)
Expand Down Expand Up @@ -46,8 +49,31 @@ withUnits t
-- |
-- | To increase benchmark accuracy by forcing garbage collection before the
-- | benchmark is run, node should be invoked with the '--expose-gc' flag.
benchWith :: forall a. Int -> (Unit -> a) -> Effect Unit
benchWith
:: forall a
. Int
-> (Unit -> a)
-> Effect Unit
benchWith n f = do
res <- benchWith' n f
log ("mean = " <> withUnits res.mean)
log ("stddev = " <> withUnits res.stdDev)
log ("min = " <> withUnits res.min)
log ("max = " <> withUnits res.max)

type BenchResult =
{ mean :: Number
, stdDev :: Number
, min :: Number
, max :: Number
}

benchWith'
:: forall a
. Int
-> (Unit -> a)
-> Effect BenchResult
benchWith' n f = do
sumRef <- Ref.new 0.0
sum2Ref <- Ref.new 0.0
minRef <- Ref.new infinity
Expand All @@ -70,10 +96,12 @@ benchWith n f = do
let n' = toNumber n
mean = sum / n'
stdDev = sqrt ((sum2 - n' * mean * mean) / (n' - 1.0))
log ("mean = " <> withUnits mean)
log ("stddev = " <> withUnits stdDev)
log ("min = " <> withUnits min')
log ("max = " <> withUnits max')
pure
{ mean
, stdDev
, min: min'
, max: max'
}

-- | Estimate the running time of a function and print a summary to the console,
-- | by running the function 1000 times.
Expand Down