diff --git a/.gitignore b/.gitignore index 9623fa5..9121a72 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /.psc* /.purs* /.psa* +package-lock.json diff --git a/.travis.yml b/.travis.yml index fdb744f..5b14646 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/package.json b/package.json index 01da16a..5a4bff0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Performance/Minibench.purs b/src/Performance/Minibench.purs index 638ad87..d7f678e 100644 --- a/src/Performance/Minibench.purs +++ b/src/Performance/Minibench.purs @@ -7,6 +7,9 @@ module Performance.Minibench ( bench , benchWith + , benchWith' + , BenchResult + , withUnits ) where import Prelude hiding (min,max) @@ -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 @@ -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.