@@ -10,10 +10,13 @@ import Data.Functor.Identity (Identity(..))
1010import Data.List (foldl' )
1111import qualified Data.Map as M
1212import qualified Data.Map.Strict as MS
13+ import qualified Data.Set as Set
1314import Data.Map (alterF )
1415import Data.Maybe (fromMaybe )
1516import Data.Functor ((<$) )
1617import Data.Coerce
18+ import Data.Tuple.Solo (Solo (MkSolo ), getSolo )
19+ import System.Random (StdGen , mkStdGen , random , randoms )
1720import Prelude hiding (lookup )
1821
1922import Utils.Fold (foldBenchmarks , foldWithKeyBenchmarks )
@@ -23,9 +26,12 @@ main = do
2326 let m = M. fromList elems :: M. Map Int Int
2427 m_even = M. fromList elems_even :: M. Map Int Int
2528 m_odd = M. fromList elems_odd :: M. Map Int Int
29+ s_random = Set. fromList keys_random :: Set. Set Int
2630 evaluate $ rnf [m, m_even, m_odd]
31+ evaluate $ rnf [s_random]
2732 evaluate $ rnf
2833 [elems_distinct_asc, elems_distinct_desc, elems_asc, elems_desc]
34+ evaluate $ rnf [keys_random]
2935 defaultMain
3036 [ bench " lookup absent" $ whnf (lookup evens) m_odd
3137 , bench " lookup present" $ whnf (lookup evens) m_even
@@ -124,6 +130,11 @@ main = do
124130 , bench " fromDistinctAscList:fusion" $ whnf (\ n -> M. fromDistinctAscList [(i,i) | i <- [1 .. n]]) bound
125131 , bench " fromDistinctDescList" $ whnf M. fromDistinctDescList elems_distinct_desc
126132 , bench " fromDistinctDescList:fusion" $ whnf (\ n -> M. fromDistinctDescList [(i,i) | i <- [n,n- 1 .. 1 ]]) bound
133+ , bench " fromSet" $ whnf (M. fromSet pred ) s_random
134+ , bench " Lazy.fromSetA outer" $ whnf (M. fromSetA (MkSolo . pred )) s_random
135+ , bench " Strict.fromSetA outer" $ whnf (MS. fromSetA (MkSolo . pred )) s_random
136+ , bench " Lazy.fromSetA inner" $ whnf (getSolo . M. fromSetA (MkSolo . pred )) s_random
137+ , bench " Strict.fromSetA inner" $ whnf (getSolo . MS. fromSetA (MkSolo . pred )) s_random
127138 , bench " minView" $ whnf (\ m' -> case M. minViewWithKey m' of {Nothing -> 0 ; Just ((k,v),m'') -> k+ v+ M. size m''}) (M. fromAscList $ zip [1 .. 10 :: Int ] [100 .. 110 :: Int ])
128139 , bench " eq" $ whnf (\ m' -> m' == m') m -- worst case, compares everything
129140 , bench " compare" $ whnf (\ m' -> compare m' m') m -- worst case, compares everything
@@ -136,7 +147,7 @@ main = do
136147 , bench " mapKeysWith:desc" $ whnf (M. mapKeysWith (+) (negate . (`div` 2 ))) m
137148 ]
138149 where
139- bound = 2 ^ 12
150+ bound = 2 ^ 14
140151 elems = shuffle elems_distinct_asc
141152 elems_even = zip evens evens
142153 elems_odd = zip odds odds
@@ -152,6 +163,7 @@ main = do
152163 values = [1 .. bound]
153164 sumkv k v1 v2 = k + v1 + v2
154165 consPair k v xs = (k, v) : xs
166+ keys_random = take bound (randoms gen)
155167
156168add3 :: Int -> Int -> Int -> Int
157169add3 x y z = x + y + z
@@ -239,3 +251,6 @@ atAltNoRules f xs m = foldl' (\m k -> runIdent (alterF (Ident . f) k m)) m xs
239251maybeDel :: Int -> Maybe Int
240252maybeDel n | n `mod` 3 == 0 = Nothing
241253 | otherwise = Just n
254+
255+ gen :: StdGen
256+ gen = mkStdGen 90
0 commit comments