Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion bench/Bench/Data/Map.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import Data.List as L
import Data.Map as M

benchMap :: Eff (console :: CONSOLE) Unit
benchMap = benchSize
benchMap = do
log "size"
log "---------------"
benchSize

log ""

log "fromFoldable"
log "------------"
benchFromFoldable

where

benchSize = do
let nats = L.range 0 999999
natPairs = (flip Tuple) unit <$> nats
Expand All @@ -31,3 +42,14 @@ benchMap = benchSize

log $ "size: big map (" <> show (M.size bigMap) <> ")"
benchWith 10 \_ -> M.size bigMap

benchFromFoldable = do
let natStrs = show <$> L.range 0 99999
natPairs = (flip Tuple) unit <$> natStrs
shortPairList = L.take 10000 natPairs

log $ "fromFoldable (" <> show (L.length shortPairList) <> ")"
benchWith 100 \_ -> M.fromFoldable shortPairList

log $ "fromFoldable (" <> show (L.length natPairs) <> ")"
benchWith 10 \_ -> M.fromFoldable natPairs
27 changes: 27 additions & 0 deletions bench/Bench/Data/StrMap.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Bench.Data.StrMap where

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

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

benchStrMap :: Eff (console :: CONSOLE) Unit
benchStrMap = do
log "fromFoldable"
benchFromFoldable

where
benchFromFoldable = do
let natStrs = show <$> L.range 0 99999
natPairs = (flip Tuple) unit <$> natStrs
shortPairList = L.take 10000 natPairs

log $ "fromFoldable (" <> show (L.length shortPairList) <> ")"
benchWith 100 \_ -> M.fromFoldable shortPairList

log $ "fromFoldable (" <> show (L.length natPairs) <> ")"
benchWith 10 \_ -> M.fromFoldable natPairs
17 changes: 14 additions & 3 deletions bench/Bench/Main.purs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
module Bench.Main where

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

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

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

log ""


log "StrMap"
log "======"
benchStrMap
8 changes: 4 additions & 4 deletions src/Data/StrMap.purs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Data.StrMap

import Prelude

import Control.Monad.Eff (Eff, runPure)
import Control.Monad.Eff (Eff, runPure, foreachE)
import Control.Monad.ST as ST

import Data.Array as A
Expand Down Expand Up @@ -204,10 +204,10 @@ update f k m = alter (maybe Nothing f) k m

-- | Create a map from a foldable collection of key/value pairs
fromFoldable :: forall f a. Foldable f => f (Tuple String a) -> StrMap a
fromFoldable l = pureST (do
fromFoldable l = pureST do
s <- SM.new
for_ l (\(Tuple k v) -> SM.poke s k v)
pure s)
foreachE (A.fromFoldable l) \(Tuple k v) -> void (SM.poke s k v)
pure s

foreign import _lookupST :: forall a h r z. Fn4 z (a -> z) String (SM.STStrMap h a) (Eff (st :: ST.ST h | r) z)

Expand Down