1{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
3{-# LANGUAGE DataKinds #-}
4{-# LANGUAGE PolyKinds #-}
5{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE TypeOperators #-}
7{-# LANGUAGE UndecidableInstances #-}
13import Prelude hiding (lookup)
15import Criterion.Main (bench, env, nf, whnf)
16import Data.Kind (Type)
17import Data.Maybe (fromJust)
18import Data.Proxy (Proxy (..))
19import Data.Typeable (Typeable)
20import GHC.TypeLits (type (+), KnownNat, Nat)
22import Data.TypeRep.CMap (TypeRepMap (..), empty, insert, lookup)
24import Spec (BenchSpec (..))
29 { benchLookup = Just $ \name ->
30 env (mkMap 10000) $ \ ~bigMap ->
31 bench name $ nf tenLookups bigMap
32 , benchInsertSmall = Just $ \name ->
33 bench name $ whnf (inserts empty 10) (Proxy @ 99999)
34 , benchInsertBig = Just $ \name ->
35 env (mkMap 10000) $ \ ~bigMap ->
36 bench name $ whnf (inserts bigMap 1) (Proxy @ 99999)
37 , benchUpdateSmall = Just $ \name ->
38 env (mkMap 10) $ \ ~smallMap ->
39 bench name $ whnf (inserts smallMap 10) (Proxy @ 0)
40 , benchUpdateBig = Just $ \name ->
41 env (mkMap 10000) $ \ ~bigMap ->
42 bench name $ whnf (inserts bigMap 10) (Proxy @ 0)
46 :: TypeRepMap (Proxy :: Nat -> Type)
47 -> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
48 , Proxy 50, Proxy 60, Proxy 70, Proxy 80
50tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
52 lp :: forall (a::Nat). Typeable a => Proxy a
53 lp = fromJust $ lookup tmap
56 :: forall a . (KnownNat a)
57 => TypeRepMap (Proxy :: Nat -> Type)
60 -> TypeRepMap (Proxy :: Nat -> Type)
62inserts !c n x = inserts
65 (Proxy :: Proxy (a+1))
67mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> Type))
68mkMap n = pure $ buildBigMap n (Proxy :: Proxy 0) empty
71 :: forall a . (KnownNat a)
74 -> TypeRepMap (Proxy :: Nat -> Type)
75 -> TypeRepMap (Proxy :: Nat -> Type)
76buildBigMap 1 x = insert x
77buildBigMap n x = insert x . buildBigMap (n - 1) (Proxy :: Proxy (a + 1))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list