Skip to content

Commit a3353c3

Browse files
authored
Merge pull request #9 from safareli/un-log
add BenchResult
2 parents 24ef98e + 129ec6c commit a3353c3

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/.psc*
77
/.purs*
88
/.psa*
9+
package-lock.json

.travis.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@ language: node_js
22
dist: trusty
33
sudo: required
44
node_js: stable
5+
env:
6+
- PATH=$HOME/purescript:$PATH
57
install:
8+
- 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')
9+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
10+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
11+
- chmod a+x $HOME/purescript
612
- npm install -g bower
713
- npm install
8-
- bower install
14+
- bower install --production
915
script:
1016
- npm run -s build
17+
- bower install
18+
- npm run -s test
19+
after_success:
20+
- >-
21+
test $TRAVIS_TAG &&
22+
echo $GITHUB_TOKEN | pulp login &&
23+
echo y | pulp publish --no-push

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build -- --censor-lib --strict"
5+
"build": "pulp build -- --censor-lib --strict",
6+
"test": "pulp test"
67
},
78
"devDependencies": {
89
"pulp": "^12.2.0",

src/Performance/Minibench.purs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
module Performance.Minibench
88
( bench
99
, benchWith
10+
, benchWith'
11+
, BenchResult
12+
, withUnits
1013
) where
1114

1215
import Prelude hiding (min,max)
@@ -46,8 +49,31 @@ withUnits t
4649
-- |
4750
-- | To increase benchmark accuracy by forcing garbage collection before the
4851
-- | benchmark is run, node should be invoked with the '--expose-gc' flag.
49-
benchWith :: forall a. Int -> (Unit -> a) -> Effect Unit
52+
benchWith
53+
:: forall a
54+
. Int
55+
-> (Unit -> a)
56+
-> Effect Unit
5057
benchWith n f = do
58+
res <- benchWith' n f
59+
log ("mean = " <> withUnits res.mean)
60+
log ("stddev = " <> withUnits res.stdDev)
61+
log ("min = " <> withUnits res.min)
62+
log ("max = " <> withUnits res.max)
63+
64+
type BenchResult =
65+
{ mean :: Number
66+
, stdDev :: Number
67+
, min :: Number
68+
, max :: Number
69+
}
70+
71+
benchWith'
72+
:: forall a
73+
. Int
74+
-> (Unit -> a)
75+
-> Effect BenchResult
76+
benchWith' n f = do
5177
sumRef <- Ref.new 0.0
5278
sum2Ref <- Ref.new 0.0
5379
minRef <- Ref.new infinity
@@ -70,10 +96,12 @@ benchWith n f = do
7096
let n' = toNumber n
7197
mean = sum / n'
7298
stdDev = sqrt ((sum2 - n' * mean * mean) / (n' - 1.0))
73-
log ("mean = " <> withUnits mean)
74-
log ("stddev = " <> withUnits stdDev)
75-
log ("min = " <> withUnits min')
76-
log ("max = " <> withUnits max')
99+
pure
100+
{ mean
101+
, stdDev
102+
, min: min'
103+
, max: max'
104+
}
77105

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

0 commit comments

Comments
 (0)