77
88module Main where
99
10+ import Data.Bifunctor (second )
1011import Control.DeepSeq (NFData )
1112import Control.Monad (replicateM )
1213import Data.Bits (testBit )
@@ -63,13 +64,36 @@ bInsert :: Benchmark
6364bInsert =
6465 bgroup
6566 " insert"
66- [ bgroup " present " bInsertPresent ,
67- bgroup " absent " bInsertAbsent
67+ [ bgroup " presentKey " bInsertPresentKey ,
68+ bgroup " absentKey " bInsertAbsentKey
6869 ]
6970
70- -- | FIXME: This is with present keys, but mostly new values
71- bInsertPresent :: [Benchmark ]
72- bInsertPresent =
71+ bInsertPresentKey :: [Benchmark ]
72+ bInsertPresentKey =
73+ [ bgroup " sameValue" bInsertPresentKeySameValue
74+ , bgroup " differentValue" bInsertPresentKeyDifferentValue
75+ ]
76+
77+ bInsertPresentKeySameValue :: [Benchmark ]
78+ bInsertPresentKeySameValue =
79+ [ bgroup'WithSizes sizes " Bytes" setupBytes b,
80+ bgroup'WithSizes sizes " Int" setupInts b
81+ ]
82+ where
83+ sizes = filter (/= 0 ) defaultSizes
84+ b s =
85+ bench (show s)
86+ . whnf (\ (m, kvs) -> foldl' (\ () (k, v) -> HM. insert k v m `seq` () ) () kvs)
87+ toKVs = take 100 . Data.List. cycle . HM. toList
88+ setupBytes size gen = do
89+ m <- genBytesMap size gen
90+ return (m, toKVs m)
91+ setupInts size gen = do
92+ m <- genIntMap size gen
93+ return (m, toKVs m)
94+
95+ bInsertPresentKeyDifferentValue :: [Benchmark ]
96+ bInsertPresentKeyDifferentValue =
7397 [ bgroup'WithSizes sizes " Bytes" setupBytes b,
7498 bgroup'WithSizes sizes " Int" setupInts b
7599 ]
@@ -78,17 +102,17 @@ bInsertPresent =
78102 b s =
79103 bench (show s)
80104 . whnf (\ (m, kvs) -> foldl' (\ () (k, v) -> HM. insert k v m `seq` () ) () kvs)
105+ toKVs = take 100 . Data.List. cycle . map (second (+ 1 )) . HM. toList
81106 setupBytes size gen = do
82107 m <- genBytesMap size gen
83- let kvs = zip (Data.List. cycle (HM. keys m)) [0 .. ]
84- return (m, take 100 kvs)
108+ return (m, toKVs m)
85109 setupInts size gen = do
86110 m <- genIntMap size gen
87- let kvs = zip (Data.List. cycle (HM. keys m)) [0 .. ]
88- return (m, take 100 kvs)
111+ return (m, toKVs m)
89112
90- bInsertAbsent :: [Benchmark ]
91- bInsertAbsent =
113+ -- TODO
114+ bInsertAbsentKey :: [Benchmark ]
115+ bInsertAbsentKey =
92116 [ bgroup' " Bytes" genBytesMapsDisjoint b,
93117 bgroup' " Int" genIntMapsDisjoint b
94118 ]
0 commit comments