@@ -1,14 +1,22 @@
1+{-# LANGUAGE DataKinds #-}
1−{-# LANGUAGE ExplicitForAll #-}
2+{-# LANGUAGE ExplicitForAll #-}
3+{-# LANGUAGE ExplicitNamespaces #-}
4+{-# LANGUAGE KindSignatures #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
5+{-# LANGUAGE ScopedTypeVariables #-}
6+{-# LANGUAGE TypeFamilies #-}
7+{-# LANGUAGE TypeOperators #-}
8+{-# LANGUAGE UndecidableInstances #-}
4−import Criterion.Main (bench, defaultMain, whnf)
10+import Criterion.Main (bench, defaultMain, nf, whnf)
6import Prelude hiding (lookup)
12import Prelude hiding (lookup)
8import Control.DeepSeq (rnf)
14import Control.DeepSeq (rnf)
9import Control.Exception.Base (evaluate)
15import Control.Exception.Base (evaluate)
16+import Data.Maybe (fromJust)
10import Data.Proxy (Proxy (..))
17import Data.Proxy (Proxy (..))
11import Data.Typeable (Typeable)
18import Data.Typeable (Typeable)
19+import GHC.TypeLits (type (-), Nat)
13import Data.TypeRep.Map (TypeRepMap (..), empty, insert, keys, lookup, size)
21import Data.TypeRep.Map (TypeRepMap (..), empty, insert, keys, lookup, size)
@@ -17,11 +25,23 @@ main = do
17 putStrLn $ "size: " ++ (show $ size bigMap)
25 putStrLn $ "size: " ++ (show $ size bigMap)
18 evaluate $ rknf bigMap
26 evaluate $ rknf bigMap
19 defaultMain
27 defaultMain
20− [ bench "lookup" $ whnf (lookup :: TypeRepMap -> Maybe Char) bigMap
28+ [ bench "lookup" $ nf tenLookups bigMap
21− , bench "insert new" $ whnf (\x -> insert x bigMap) (111 :: Int)
29+ , bench "insert new" $ whnf (\x -> rknf $ insert x bigMap) (111 :: Int)
22− , bench "update old" $ whnf (\x -> insert x bigMap) 'b'
30+ , bench "update old" $ whnf (\x -> rknf $ insert x bigMap) 'b'
33+tenLookups :: TypeRepMap
34+ -> ( Proxy (BigProxy 10), Proxy (BigProxy 20)
35+ , Proxy (BigProxy 30), Proxy (BigProxy 40)
36+ , Proxy (BigProxy 50), Proxy (BigProxy 60)
37+ , Proxy (BigProxy 70), Proxy (BigProxy 80)
38+ -- , Proxy (BigProxy 9000), Proxy (BigProxy 10000)
40+tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
42+ lp :: Typeable a => Proxy a
43+ lp = fromJust $ lookup tmap
25-- TypeRepMap of 10000 elements
45-- TypeRepMap of 10000 elements
26bigMap :: TypeRepMap
46bigMap :: TypeRepMap
27bigMap = buildBigMap 10000 (Proxy :: Proxy Z) empty
47bigMap = buildBigMap 10000 (Proxy :: Proxy Z) empty
@@ -35,3 +55,7 @@ buildBigMap n x = insert x . buildBigMap (n - 1) (Proxy :: Proxy (S a))
36rknf :: TypeRepMap -> ()
56rknf :: TypeRepMap -> ()
37rknf = rnf . keys
57rknf = rnf . keys
59+type family BigProxy (n :: Nat) :: * where
61+ BigProxy n = S (BigProxy (n - 1))