Skip to content

Commit

Permalink
simple benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewleon committed Jun 5, 2017
1 parent 2cd994e commit ba448df
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
32 changes: 32 additions & 0 deletions bench/Bench/Data/Map.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Bench.Data.Map where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Performance.Minibench (bench)

import Data.Tuple (Tuple(..))
import Data.List as L
import Data.Map as M

benchMap :: Eff (console :: CONSOLE) Unit
benchMap = do
log "insertion benchmark"
benchInsert

log ""

log "lookup benchmark"
benchLookup

benchInsert :: Eff (console :: CONSOLE) Unit
benchInsert =
let natPairs = (flip Tuple) unit <$> L.range 0 999999
bigMap = M.fromFoldable $ natPairs
in bench \_ -> M.insert 0 unit bigMap

benchLookup :: Eff (console :: CONSOLE) Unit
benchLookup =
let natPairs = (flip Tuple) unit <$> L.range 0 999999
bigMap = M.fromFoldable $ natPairs
in bench \_ -> M.lookup 0 bigMap
32 changes: 32 additions & 0 deletions bench/Bench/Data/StrMap.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Bench.Data.StrMap where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Performance.Minibench (bench)

import Data.Tuple (Tuple(..))
import Data.List as L
import Data.Map as M

benchStrMap :: Eff (console :: CONSOLE) Unit
benchStrMap = do
log "insertion benchmark"
benchInsert

log ""

log "lookup benchmark"
benchLookup

benchInsert :: Eff (console :: CONSOLE) Unit
benchInsert =
let natPairs = (flip Tuple) unit <<< show <$> L.range 0 999999
bigMap = M.fromFoldable $ natPairs
in bench \_ -> M.insert "0" unit bigMap

benchLookup :: Eff (console :: CONSOLE) Unit
benchLookup =
let natPairs = (flip Tuple) unit <<< show <$> L.range 0 999999
bigMap = M.fromFoldable $ natPairs
in bench \_ -> M.lookup "0" bigMap
20 changes: 20 additions & 0 deletions bench/Bench/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Bench.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)

import Bench.Data.Map (benchMap)
import Bench.Data.StrMap (benchStrMap)

main :: Eff (console :: CONSOLE) Unit
main = do
log "Map benchmarks"
log "=============="
benchMap

log ""

log "StrMap benchmarks"
log "===================="
benchStrMap
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"purescript-st": "^3.0.0"
},
"devDependencies": {
"purescript-quickcheck": "^4.0.0"
"purescript-quickcheck": "^4.0.0",
"purescript-minibench": "^1.0.0"
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test"
"test": "pulp test",

"bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'",
"bench:run": "node -e 'require(\"./output/Bench.Main/index.js\").main()'",
"bench": "npm run bench:build && npm run bench:run"
},
"devDependencies": {
"eslint": "^3.17.1",
Expand Down

0 comments on commit ba448df

Please sign in to comment.