on main help sign in
Fix the DMap benchmark (#41)
commite7ac7accf469b4d525c701b252234c4f2a988efe authorVladislav Zavialov <vlad.z.4096@gmail.com> dateWed 11 Jul 2018, 12:13 (8 years ago) parent6d75c11
1 file changed+10−9
benchmark/DMap.hs+10−9
benchmark/DMap.hs+10−9
@@ -21,7 +21,6 @@ import Prelude hiding (lookup)
2121
2222import Control.DeepSeq (rnf)
2323import Control.Exception
24−import Data.Functor.Identity (Identity (..))
2524import Data.Maybe (fromJust)
2625import Data.Proxy (Proxy (..))
2726import Data.Type.Equality ((:~:) (..))
@@ -34,6 +33,8 @@ import Data.Dependent.Map (DMap, empty, insert, keys, lookup)
3433import Data.GADT.Compare (GCompare (..), GEq (..), GOrdering (..))
3534import Data.Some (Some (This))
3635
36+type TypeRepMap = DMap TypeRep
37+
3738benchDMap :: Benchmark
3839benchDMap = bgroup "dependent map"
3940 [ bench "lookup" $ nf tenLookups bigMap
@@ -41,29 +42,29 @@ benchDMap = bgroup "dependent map"
4142 -- , bench "update old" $ whnf (\x -> rknf $ insert x bigMap) (Proxy :: Proxy 1)
4243 ]
4344
44−tenLookups :: DMap TypeRep Identity
45+tenLookups :: TypeRepMap (Proxy :: Nat -> *)
4546 -> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
4647 , Proxy 50, Proxy 60, Proxy 70, Proxy 80
4748 )
4849tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
4950 where
5051 lp :: forall (a :: Nat) . Typeable a => Proxy a
51− lp = runIdentity $ fromJust $ lookup (typeRep @(Proxy a)) tmap
52+ lp = fromJust $ lookup (typeRep @a) tmap
5253
5354-- TypeRepMap of 10000 elements
54−bigMap :: DMap TypeRep Identity
55+bigMap :: TypeRepMap (Proxy :: Nat -> *)
5556bigMap = buildBigMap 10000 (Proxy :: Proxy 0) empty
5657
5758buildBigMap :: forall a . (KnownNat a)
5859 => Int
5960 -> Proxy (a :: Nat)
60− -> DMap TypeRep Identity
61− -> DMap TypeRep Identity
62−buildBigMap 1 x = insert (typeRep @(Proxy a)) $ Identity x
63−buildBigMap n x = insert (typeRep @(Proxy a)) (Identity x)
61+ -> TypeRepMap (Proxy :: Nat -> *)
62+ -> TypeRepMap (Proxy :: Nat -> *)
63+buildBigMap 1 x = insert (typeRep @a) x
64+buildBigMap n x = insert (typeRep @a) x
6465 . buildBigMap (n - 1) (Proxy @(a + 1))
6566
66−rknf :: DMap TypeRep f -> ()
67+rknf :: TypeRepMap f -> ()
6768rknf = rnf . map (\(This t) -> typeRepFingerprint t) . keys
6869
6970prepareBenchDMap :: IO ()