From 63f800412fb70bd7b43392907ff3ef61b2d2ff27 Mon Sep 17 00:00:00 2001 From: Irakli Safareli Date: Wed, 13 Dec 2017 00:28:06 +0100 Subject: [PATCH 1/4] add BenchResult --- src/Performance/Minibench.purs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Performance/Minibench.purs b/src/Performance/Minibench.purs index 31197ed..ab1b7d2 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 Control.Monad.Eff (Eff, forE) @@ -50,7 +53,26 @@ benchWith . Int -> (Unit -> a) -> Eff (console :: CONSOLE | eff) Unit -benchWith n f = runST do +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 eff a + . Int + -> (Unit -> a) + -> Eff eff BenchResult +benchWith' n f = runST do sumRef <- newSTRef 0.0 sum2Ref <- newSTRef 0.0 minRef <- newSTRef infinity @@ -73,10 +95,12 @@ benchWith n f = runST 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. From 24ef98e3aee7ae4a61fb308aec7c4fe846777be4 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 29 Apr 2018 23:32:49 +0100 Subject: [PATCH 2/4] Updates for 0.12 --- bower.json | 28 +++++++++-------- package.json | 9 +++--- src/Performance/Minibench.purs | 56 +++++++++++++++------------------- test/Main.purs | 7 +++-- 4 files changed, 49 insertions(+), 51 deletions(-) diff --git a/bower.json b/bower.json index 93a0dfc..d1a21ea 100644 --- a/bower.json +++ b/bower.json @@ -1,21 +1,25 @@ { "name": "purescript-minibench", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], + "homepage": "https://github.com/purescript/purescript-minibench", "license": "MIT", "repository": { "type": "git", - "url": "git://github.com/paf31/purescript-minibench.git" + "url": "git://github.com/purescript/purescript-minibench.git" }, + "ignore": [ + "**/.*", + "bower_components", + "node_modules", + "output", + "test", + "bower.json", + "package.json" + ], "dependencies": { - "purescript-prelude": "^3.0.0", - "purescript-console": "^3.0.0", - "purescript-integers": "^3.0.0", - "purescript-st": "^3.0.0", - "purescript-partial": "^1.2.0" + "purescript-prelude": "#compiler/0.12", + "purescript-console": "#compiler/0.12", + "purescript-integers": "#compiler/0.12", + "purescript-refs": "#compiler/0.12", + "purescript-partial": "#compiler/0.12" } } diff --git a/package.json b/package.json index e6343ef..01da16a 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,11 @@ "private": true, "scripts": { "clean": "rimraf output && rimraf .pulp-cache", - "build": "pulp build && pulp test" + "build": "pulp build -- --censor-lib --strict" }, "devDependencies": { - "pulp": "^11.0.0", - "purescript-psa": "^0.5.0", - "purescript": "^0.11.1", - "rimraf": "^2.5.4" + "pulp": "^12.2.0", + "purescript-psa": "^0.6.0", + "rimraf": "^2.6.2" } } diff --git a/src/Performance/Minibench.purs b/src/Performance/Minibench.purs index 31197ed..638ad87 100644 --- a/src/Performance/Minibench.purs +++ b/src/Performance/Minibench.purs @@ -9,22 +9,23 @@ module Performance.Minibench , benchWith ) where -import Control.Monad.Eff (Eff, forE) -import Control.Monad.Eff.Console (CONSOLE, log) -import Control.Monad.Eff.Uncurried (EffFn1, runEffFn1) -import Control.Monad.ST (modifySTRef, newSTRef, readSTRef, runST) +import Prelude hiding (min,max) + import Data.Int (toNumber) +import Effect (Effect, forE) +import Effect.Console (log) +import Effect.Ref as Ref +import Effect.Uncurried (EffectFn1, runEffectFn1) import Global (infinity) import Math (max, min, sqrt) import Partial.Unsafe (unsafeCrashWith) -import Prelude hiding (min,max) -- | A wrapper around the Node `process.hrtime()` function. -foreign import hrTime :: forall eff. EffFn1 eff (Array Int) (Array Int) +foreign import hrTime :: EffectFn1 (Array Int) (Array Int) -- | Force garbage collection. -- | Requires node to be run with the --force-gc flag. -foreign import gc :: forall eff. Eff eff Unit +foreign import gc :: Effect Unit foreign import toFixed :: Number -> String @@ -45,31 +46,27 @@ 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 eff a - . Int - -> (Unit -> a) - -> Eff (console :: CONSOLE | eff) Unit -benchWith n f = runST do - sumRef <- newSTRef 0.0 - sum2Ref <- newSTRef 0.0 - minRef <- newSTRef infinity - maxRef <- newSTRef 0.0 +benchWith :: forall a. Int -> (Unit -> a) -> Effect Unit +benchWith n f = do + sumRef <- Ref.new 0.0 + sum2Ref <- Ref.new 0.0 + minRef <- Ref.new infinity + maxRef <- Ref.new 0.0 gc forE 0 n \_ -> do - t1 <- runEffFn1 hrTime [0, 0] - t2 <- const (runEffFn1 hrTime t1) (f unit) + t1 <- runEffectFn1 hrTime [0, 0] + t2 <- const (runEffectFn1 hrTime t1) (f unit) let ns = fromHrTime t2 square = ns * ns - _ <- modifySTRef sumRef (_ + ns) - _ <- modifySTRef sum2Ref (_ + square) - _ <- modifySTRef minRef (_ `min` ns) - _ <- modifySTRef maxRef (_ `max` ns) + _ <- Ref.modify (_ + ns) sumRef + _ <- Ref.modify (_ + square) sum2Ref + _ <- Ref.modify (_ `min` ns) minRef + _ <- Ref.modify (_ `max` ns) maxRef pure unit - sum <- readSTRef sumRef - sum2 <- readSTRef sum2Ref - min' <- readSTRef minRef - max' <- readSTRef maxRef + sum <- Ref.read sumRef + sum2 <- Ref.read sum2Ref + min' <- Ref.read minRef + max' <- Ref.read maxRef let n' = toNumber n mean = sum / n' stdDev = sqrt ((sum2 - n' * mean * mean) / (n' - 1.0)) @@ -92,8 +89,5 @@ benchWith n f = runST do -- | mean = 414.00 μs -- | stddev = 494.82 μs -- | ``` -bench - :: forall eff a - . (Unit -> a) - -> Eff (console :: CONSOLE | eff) Unit +bench :: forall a. (Unit -> a) -> Effect Unit bench = benchWith 1000 diff --git a/test/Main.purs b/test/Main.purs index 943e242..e0def90 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,11 +1,12 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE, log) + +import Effect (Effect) +import Effect.Console (log) import Performance.Minibench (bench, benchWith) -main :: forall e. Eff (console :: CONSOLE | e) Unit +main :: Effect Unit main = do let loop 0 = 0 loop n = loop (n - 1) From 129ec6cb48bc0f6be5e3348dcfd1e1217f6bf4de Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Tue, 22 May 2018 16:40:43 +0100 Subject: [PATCH 3/4] Update build --- .gitignore | 1 + .travis.yml | 15 ++++++++++++++- package.json | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) 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", From 1f443775572eddd7a64f01813f1886da53adafd8 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Wed, 23 May 2018 01:36:51 +0100 Subject: [PATCH 4/4] Update dependencies, license --- LICENSE | 38 ++++++++++++++++++++++---------------- bower.json | 15 +++++++++------ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/LICENSE b/LICENSE index 453f5d3..311379c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,20 +1,26 @@ -The MIT License (MIT) +Copyright 2018 PureScript -Copyright (c) 2017 Phil Freeman +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bower.json b/bower.json index d1a21ea..3d08d53 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "purescript-minibench", "homepage": "https://github.com/purescript/purescript-minibench", - "license": "MIT", + "license": "BSD-3-Clause", "repository": { "type": "git", "url": "git://github.com/purescript/purescript-minibench.git" @@ -16,10 +16,13 @@ "package.json" ], "dependencies": { - "purescript-prelude": "#compiler/0.12", - "purescript-console": "#compiler/0.12", - "purescript-integers": "#compiler/0.12", - "purescript-refs": "#compiler/0.12", - "purescript-partial": "#compiler/0.12" + "purescript-console": "^4.0.0", + "purescript-effect": "^2.0.0", + "purescript-globals": "^4.0.0", + "purescript-integers": "^4.0.0", + "purescript-math": "^2.1.1", + "purescript-partial": "^2.0.0", + "purescript-prelude": "^4.0.0", + "purescript-refs": "^4.0.0" } }