Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more efficient unionWith, eliminate transformation Map to List in Foldable{WithIndex} instances. #60

Merged
merged 6 commits into from
Apr 22, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Breaking changes:
New features:
- Exported `Data.Map.Internal` data constructors (#52 by @natefaubion)
- Add unbiased `Semigroup`/`Monoid` instances to `Map` with `Warn` (#54 by @JordanMartinez)
- Improved speed of `foldr`, `foldl`, `foldMap`, `foldlWithIndex`, `foldrWithIndex`, `foldMapWithIndex`, `unionWith` (#60 by @xgrommx)

Bugfixes:

Expand Down
77 changes: 77 additions & 0 deletions bench/Bench/Data/Map.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Prelude

import Data.List as L
import Data.Map as M
import Bench.Data.Map2a0bff as Map2a0bff
import Data.Foldable as F
import Data.FoldableWithIndex as FI
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Console (log)
Expand All @@ -21,8 +24,38 @@ benchMap = do
log "------------"
benchFromFoldable

log ""

log "Foldable"
log "---------------"
benchFoldable

log ""

log "union"
log "---------------"
benchUnion

where

benchUnion = do
let nats = L.range 0 999999
nats2 = L.range 999999 1999999
natPairs = (flip Tuple) unit <$> nats
natPairs2 = (flip Tuple) unit <$> nats2
bigMap = Map2a0bff.fromFoldable $ natPairs
bigMap2 = Map2a0bff.fromFoldable $ natPairs2
bigMap' = M.fromFoldable $ natPairs
bigMap2' = M.fromFoldable $ natPairs2
size = Map2a0bff.size bigMap
size' = M.size bigMap'

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

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

benchSize = do
let nats = L.range 0 999999
natPairs = (flip Tuple) unit <$> nats
Expand All @@ -43,6 +76,50 @@ benchMap = do
log $ "size: big map (" <> show (M.size bigMap) <> ")"
benchWith 10 \_ -> M.size bigMap

benchFoldable = do
let nats = L.range 0 999999
natPairs = (flip Tuple) unit <$> nats
bigMap = Map2a0bff.fromFoldable $ natPairs
bigMap' = M.fromFoldable $ natPairs
size = Map2a0bff.size bigMap
size' = M.size bigMap'

log $ "Map2a0bff.foldr big map (" <> show size <> ")"
benchWith 10 \_ -> F.foldr (\_ _ -> unit) unit bigMap

log $ "M.foldr big map (" <> show size' <> ")"
benchWith 10 \_ -> F.foldr (\_ _ -> unit) unit bigMap'

log $ "Map2a0bff.foldl big map (" <> show size <> ")"
benchWith 10 \_ -> F.foldl (\_ _ -> unit) unit bigMap

log $ "M.foldl big map (" <> show size' <> ")"
benchWith 10 \_ -> F.foldl (\_ _ -> unit) unit bigMap'

log $ "Map2a0bff.foldMap big map (" <> show size <> ")"
benchWith 10 \_ -> F.foldMap (\_ -> unit) bigMap

log $ "M.foldMap big map (" <> show size' <> ")"
benchWith 10 \_ -> F.foldMap (\_ -> unit) bigMap'

log $ "Map2a0bff.foldrWithIndex big map (" <> show size <> ")"
benchWith 10 \_ -> FI.foldrWithIndex (\_ _ _ -> unit) unit bigMap

log $ "M.foldrWithIndex big map (" <> show size' <> ")"
benchWith 10 \_ -> FI.foldrWithIndex (\_ _ _ -> unit) unit bigMap'

log $ "Map2a0bff.foldlWithIndex big map (" <> show size <> ")"
benchWith 10 \_ -> FI.foldlWithIndex (\_ _ _ -> unit) unit bigMap

log $ "M.foldlWithIndex big map (" <> show size' <> ")"
benchWith 10 \_ -> FI.foldlWithIndex (\_ _ _ -> unit) unit bigMap'

log $ "Map2a0bff.foldMapWithIndex big map (" <> show size <> ")"
benchWith 10 \_ -> FI.foldMapWithIndex (\_ _ -> unit) bigMap

log $ "M.foldMapWithIndex big map (" <> show size' <> ")"
benchWith 10 \_ -> FI.foldMapWithIndex (\_ _ -> unit) bigMap'

benchFromFoldable = do
let natStrs = show <$> L.range 0 99999
natPairs = (flip Tuple) unit <$> natStrs
Expand Down
Loading