Skip to content

Commit b763dc2

Browse files
committed
Merge branch 'compiler/0.12' into un-log
2 parents 63f8004 + 24ef98e commit b763dc2

File tree

4 files changed

+53
-51
lines changed

4 files changed

+53
-51
lines changed

bower.json

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
{
22
"name": "purescript-minibench",
3-
"ignore": [
4-
"**/.*",
5-
"node_modules",
6-
"bower_components",
7-
"output"
8-
],
3+
"homepage": "https://github.com/purescript/purescript-minibench",
94
"license": "MIT",
105
"repository": {
116
"type": "git",
12-
"url": "git://github.com/paf31/purescript-minibench.git"
7+
"url": "git://github.com/purescript/purescript-minibench.git"
138
},
9+
"ignore": [
10+
"**/.*",
11+
"bower_components",
12+
"node_modules",
13+
"output",
14+
"test",
15+
"bower.json",
16+
"package.json"
17+
],
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-prelude": "#compiler/0.12",
20+
"purescript-console": "#compiler/0.12",
21+
"purescript-integers": "#compiler/0.12",
22+
"purescript-refs": "#compiler/0.12",
23+
"purescript-partial": "#compiler/0.12"
2024
}
2125
}

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
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"
66
},
77
"devDependencies": {
8-
"pulp": "^11.0.0",
9-
"purescript-psa": "^0.5.0",
10-
"purescript": "^0.11.1",
11-
"rimraf": "^2.5.4"
8+
"pulp": "^12.2.0",
9+
"purescript-psa": "^0.6.0",
10+
"rimraf": "^2.6.2"
1211
}
1312
}

src/Performance/Minibench.purs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ module Performance.Minibench
1212
, withUnits
1313
) where
1414

15-
import Control.Monad.Eff (Eff, forE)
16-
import Control.Monad.Eff.Console (CONSOLE, log)
17-
import Control.Monad.Eff.Uncurried (EffFn1, runEffFn1)
18-
import Control.Monad.ST (modifySTRef, newSTRef, readSTRef, runST)
15+
import Prelude hiding (min,max)
16+
1917
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)
2022
import Global (infinity)
2123
import Math (max, min, sqrt)
2224
import Partial.Unsafe (unsafeCrashWith)
23-
import Prelude hiding (min,max)
2425

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

2829
-- | Force garbage collection.
2930
-- | Requires node to be run with the --force-gc flag.
30-
foreign import gc :: forall eff. Eff eff Unit
31+
foreign import gc :: Effect Unit
3132

3233
foreign import toFixed :: Number -> String
3334

@@ -49,49 +50,49 @@ withUnits t
4950
-- | To increase benchmark accuracy by forcing garbage collection before the
5051
-- | benchmark is run, node should be invoked with the '--expose-gc' flag.
5152
benchWith
52-
:: forall eff a
53+
:: forall a
5354
. Int
5455
-> (Unit -> a)
55-
-> Eff (console :: CONSOLE | eff) Unit
56+
-> Effect Unit
5657
benchWith n f = do
5758
res <- benchWith' n f
5859
log ("mean = " <> withUnits res.mean)
5960
log ("stddev = " <> withUnits res.stdDev)
6061
log ("min = " <> withUnits res.min)
6162
log ("max = " <> withUnits res.max)
6263

63-
type BenchResult =
64+
type BenchResult =
6465
{ mean :: Number
6566
, stdDev :: Number
6667
, min :: Number
6768
, max :: Number
6869
}
6970

7071
benchWith'
71-
:: forall eff a
72+
:: forall a
7273
. Int
7374
-> (Unit -> a)
74-
-> Eff eff BenchResult
75-
benchWith' n f = runST do
76-
sumRef <- newSTRef 0.0
77-
sum2Ref <- newSTRef 0.0
78-
minRef <- newSTRef infinity
79-
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
8081
gc
8182
forE 0 n \_ -> do
82-
t1 <- runEffFn1 hrTime [0, 0]
83-
t2 <- const (runEffFn1 hrTime t1) (f unit)
83+
t1 <- runEffectFn1 hrTime [0, 0]
84+
t2 <- const (runEffectFn1 hrTime t1) (f unit)
8485
let ns = fromHrTime t2
8586
square = ns * ns
86-
_ <- modifySTRef sumRef (_ + ns)
87-
_ <- modifySTRef sum2Ref (_ + square)
88-
_ <- modifySTRef minRef (_ `min` ns)
89-
_ <- 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
9091
pure unit
91-
sum <- readSTRef sumRef
92-
sum2 <- readSTRef sum2Ref
93-
min' <- readSTRef minRef
94-
max' <- readSTRef maxRef
92+
sum <- Ref.read sumRef
93+
sum2 <- Ref.read sum2Ref
94+
min' <- Ref.read minRef
95+
max' <- Ref.read maxRef
9596
let n' = toNumber n
9697
mean = sum / n'
9798
stdDev = sqrt ((sum2 - n' * mean * mean) / (n' - 1.0))
@@ -116,8 +117,5 @@ benchWith' n f = runST do
116117
-- | mean = 414.00 μs
117118
-- | stddev = 494.82 μs
118119
-- | ```
119-
bench
120-
:: forall eff a
121-
. (Unit -> a)
122-
-> Eff (console :: CONSOLE | eff) Unit
120+
bench :: forall a. (Unit -> a) -> Effect Unit
123121
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)