Skip to content

Commit

Permalink
Add benchmarks for {Set,Map}.fromAscList and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
meooow25 committed Jul 14, 2023
1 parent bf3fca9 commit 1b08c4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions containers-tests/benchmarks/Map.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ main = do
m_even = M.fromAscList elems_even :: M.Map Int Int
m_odd = M.fromAscList elems_odd :: M.Map Int Int
evaluate $ rnf [m, m_even, m_odd]
evaluate $ rnf elems_rev
evaluate $ rnf [elems_rev, elems_asc, elems_desc]
defaultMain
[ bench "lookup absent" $ whnf (lookup evens) m_odd
, bench "lookup present" $ whnf (lookup evens) m_even
Expand Down Expand Up @@ -89,7 +89,8 @@ main = do
, bench "split" $ whnf (M.split (bound `div` 2)) m
, bench "fromList" $ whnf M.fromList elems
, bench "fromList-desc" $ whnf M.fromList (reverse elems)
, bench "fromAscList" $ whnf M.fromAscList elems
, bench "fromAscList" $ whnf M.fromAscList elems_asc
, bench "fromDescList" $ whnf M.fromDescList elems_desc
, bench "fromDistinctAscList" $ whnf M.fromDistinctAscList elems
, bench "fromDistinctAscList:fusion" $ whnf (\n -> M.fromDistinctAscList [(i,i) | i <- [1..n]]) bound
, bench "fromDistinctDescList" $ whnf M.fromDistinctDescList elems_rev
Expand All @@ -102,6 +103,10 @@ main = do
elems_even = zip evens evens
elems_odd = zip odds odds
elems_rev = reverse elems
keys_asc = map (`div` 2) [1..bound]
elems_asc = zip keys_asc values
keys_desc = map (`div` 2) [bound,bound-1..1]
elems_desc = zip keys_desc values
keys = [1..bound]
evens = [2,4..bound]
odds = [1,3..bound]
Expand Down
7 changes: 5 additions & 2 deletions containers-tests/benchmarks/Set.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ main = do
s_odd = S.fromAscList elems_odd :: S.Set Int
strings_s = S.fromList strings
evaluate $ rnf [s, s_even, s_odd]
evaluate $ rnf elems_rev
evaluate $ rnf [elems_rev, elems_asc, elems_desc]
defaultMain
[ bench "member" $ whnf (member elems) s
, bench "insert" $ whnf (ins elems) S.empty
Expand All @@ -33,9 +33,10 @@ main = do
, bench "intersection" $ whnf (S.intersection s) s_even
, bench "fromList" $ whnf S.fromList elems
, bench "fromList-desc" $ whnf S.fromList (reverse elems)
, bench "fromAscList" $ whnf S.fromAscList elems
, bench "fromAscList" $ whnf S.fromAscList elems_asc
, bench "fromDistinctAscList" $ whnf S.fromDistinctAscList elems
, bench "fromDistinctAscList:fusion" $ whnf (\n -> S.fromDistinctAscList [1..n]) bound
, bench "fromDescList" $ whnf S.fromDescList elems_desc
, bench "fromDistinctDescList" $ whnf S.fromDistinctDescList elems_rev
, bench "fromDistinctDescList:fusion" $ whnf (\n -> S.fromDistinctDescList [n,n-1..1]) bound
, bench "disjoint:false" $ whnf (S.disjoint s) s_even
Expand All @@ -62,6 +63,8 @@ main = do
elems_even = [2,4..bound]
elems_odd = [1,3..bound]
elems_rev = reverse elems
elems_asc = map (`div` 2) [1..bound]
elems_desc = map (`div` 2) [bound,bound-1..1]
strings = map show elems

member :: [Int] -> S.Set Int -> Int
Expand Down

0 comments on commit 1b08c4b

Please sign in to comment.