Skip to content

Commit a9cc6d7

Browse files
authored
Merge pull request #10 from purescript/compiler/0.12
Update for PureScript 0.12
2 parents 56f6300 + 1f44377 commit a9cc6d7

File tree

7 files changed

+119
-69
lines changed

7 files changed

+119
-69
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

LICENSE

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
The MIT License (MIT)
1+
Copyright 2018 PureScript
22

3-
Copyright (c) 2017 Phil Freeman
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
45

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
the Software, and to permit persons to whom the Software is furnished to do so,
10-
subject to the following conditions:
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
118

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation and/or
11+
other materials provided with the distribution.
1412

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bower.json

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
{
22
"name": "purescript-minibench",
3+
"homepage": "https://github.com/purescript/purescript-minibench",
4+
"license": "BSD-3-Clause",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/purescript/purescript-minibench.git"
8+
},
39
"ignore": [
410
"**/.*",
5-
"node_modules",
611
"bower_components",
7-
"output"
12+
"node_modules",
13+
"output",
14+
"test",
15+
"bower.json",
16+
"package.json"
817
],
9-
"license": "MIT",
10-
"repository": {
11-
"type": "git",
12-
"url": "git://github.com/paf31/purescript-minibench.git"
13-
},
1418
"dependencies": {
15-
"purescript-prelude": "^3.0.0",
16-
"purescript-console": "^3.0.0",
17-
"purescript-integers": "^3.0.0",
18-
"purescript-st": "^3.0.0",
19-
"purescript-partial": "^1.2.0"
19+
"purescript-console": "^4.0.0",
20+
"purescript-effect": "^2.0.0",
21+
"purescript-globals": "^4.0.0",
22+
"purescript-integers": "^4.0.0",
23+
"purescript-math": "^2.1.1",
24+
"purescript-partial": "^2.0.0",
25+
"purescript-prelude": "^4.0.0",
26+
"purescript-refs": "^4.0.0"
2027
}
2128
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build && pulp test"
5+
"build": "pulp build -- --censor-lib --strict",
6+
"test": "pulp test"
67
},
78
"devDependencies": {
8-
"pulp": "^11.0.0",
9-
"purescript-psa": "^0.5.0",
10-
"purescript": "^0.11.1",
11-
"rimraf": "^2.5.4"
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
1212
}
1313
}

src/Performance/Minibench.purs

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

12-
import Control.Monad.Eff (Eff, forE)
13-
import Control.Monad.Eff.Console (CONSOLE, log)
14-
import Control.Monad.Eff.Uncurried (EffFn1, runEffFn1)
15-
import Control.Monad.ST (modifySTRef, newSTRef, readSTRef, runST)
15+
import Prelude hiding (min,max)
16+
1617
import Data.Int (toNumber)
18+
import Effect (Effect, forE)
19+
import Effect.Console (log)
20+
import Effect.Ref as Ref
21+
import Effect.Uncurried (EffectFn1, runEffectFn1)
1722
import Global (infinity)
1823
import Math (max, min, sqrt)
1924
import Partial.Unsafe (unsafeCrashWith)
20-
import Prelude hiding (min,max)
2125

2226
-- | A wrapper around the Node `process.hrtime()` function.
23-
foreign import hrTime :: forall eff. EffFn1 eff (Array Int) (Array Int)
27+
foreign import hrTime :: EffectFn1 (Array Int) (Array Int)
2428

2529
-- | Force garbage collection.
2630
-- | Requires node to be run with the --force-gc flag.
27-
foreign import gc :: forall eff. Eff eff Unit
31+
foreign import gc :: Effect Unit
2832

2933
foreign import toFixed :: Number -> String
3034

@@ -46,37 +50,58 @@ withUnits t
4650
-- | To increase benchmark accuracy by forcing garbage collection before the
4751
-- | benchmark is run, node should be invoked with the '--expose-gc' flag.
4852
benchWith
49-
:: forall eff a
53+
:: forall a
54+
. Int
55+
-> (Unit -> a)
56+
-> Effect Unit
57+
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
5073
. Int
5174
-> (Unit -> a)
52-
-> Eff (console :: CONSOLE | eff) Unit
53-
benchWith n f = runST do
54-
sumRef <- newSTRef 0.0
55-
sum2Ref <- newSTRef 0.0
56-
minRef <- newSTRef infinity
57-
maxRef <- newSTRef 0.0
75+
-> Effect BenchResult
76+
benchWith' n f = do
77+
sumRef <- Ref.new 0.0
78+
sum2Ref <- Ref.new 0.0
79+
minRef <- Ref.new infinity
80+
maxRef <- Ref.new 0.0
5881
gc
5982
forE 0 n \_ -> do
60-
t1 <- runEffFn1 hrTime [0, 0]
61-
t2 <- const (runEffFn1 hrTime t1) (f unit)
83+
t1 <- runEffectFn1 hrTime [0, 0]
84+
t2 <- const (runEffectFn1 hrTime t1) (f unit)
6285
let ns = fromHrTime t2
6386
square = ns * ns
64-
_ <- modifySTRef sumRef (_ + ns)
65-
_ <- modifySTRef sum2Ref (_ + square)
66-
_ <- modifySTRef minRef (_ `min` ns)
67-
_ <- modifySTRef maxRef (_ `max` ns)
87+
_ <- Ref.modify (_ + ns) sumRef
88+
_ <- Ref.modify (_ + square) sum2Ref
89+
_ <- Ref.modify (_ `min` ns) minRef
90+
_ <- Ref.modify (_ `max` ns) maxRef
6891
pure unit
69-
sum <- readSTRef sumRef
70-
sum2 <- readSTRef sum2Ref
71-
min' <- readSTRef minRef
72-
max' <- readSTRef maxRef
92+
sum <- Ref.read sumRef
93+
sum2 <- Ref.read sum2Ref
94+
min' <- Ref.read minRef
95+
max' <- Ref.read maxRef
7396
let n' = toNumber n
7497
mean = sum / n'
7598
stdDev = sqrt ((sum2 - n' * mean * mean) / (n' - 1.0))
76-
log ("mean = " <> withUnits mean)
77-
log ("stddev = " <> withUnits stdDev)
78-
log ("min = " <> withUnits min')
79-
log ("max = " <> withUnits max')
99+
pure
100+
{ mean
101+
, stdDev
102+
, min: min'
103+
, max: max'
104+
}
80105

81106
-- | Estimate the running time of a function and print a summary to the console,
82107
-- | by running the function 1000 times.
@@ -92,8 +117,5 @@ benchWith n f = runST do
92117
-- | mean = 414.00 μs
93118
-- | stddev = 494.82 μs
94119
-- | ```
95-
bench
96-
:: forall eff a
97-
. (Unit -> a)
98-
-> Eff (console :: CONSOLE | eff) Unit
120+
bench :: forall a. (Unit -> a) -> Effect Unit
99121
bench = benchWith 1000

test/Main.purs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module Test.Main where
22

33
import Prelude
4-
import Control.Monad.Eff (Eff)
5-
import Control.Monad.Eff.Console (CONSOLE, log)
4+
5+
import Effect (Effect)
6+
import Effect.Console (log)
67
import Performance.Minibench (bench, benchWith)
78

8-
main :: forall e. Eff (console :: CONSOLE | e) Unit
9+
main :: Effect Unit
910
main = do
1011
let loop 0 = 0
1112
loop n = loop (n - 1)

0 commit comments

Comments
 (0)