1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE ExplicitForAll #-}
3{-# LANGUAGE ExplicitNamespaces #-}
4{-# LANGUAGE KindSignatures #-}
5{-# LANGUAGE PolyKinds #-}
6{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TypeFamilies #-}
8{-# LANGUAGE TypeOperators #-}
9{-# LANGUAGE UndecidableInstances #-}
11{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
18import Criterion.Main (Benchmark, bench, bgroup, nf)
20import Prelude hiding (lookup)
22import Control.Exception
23import Control.DeepSeq (rnf)
24import Data.Maybe (fromJust)
25import Data.Proxy (Proxy (..))
26import Data.Typeable (Typeable)
29import Data.TypeRep.Map (TypeRepMap (..), empty, insert, lookup, keys)
32benchMap = bgroup "map"
33 [ bench "lookup" $ nf tenLookups bigMap
34 --, bench "insert new" $ whnf (\x -> rknf $ insert x bigMap) (Proxy :: Proxy 9999999999)
35 --, bench "update old" $ whnf (\x -> rknf $ insert x bigMap) (Proxy :: Proxy 1)
38tenLookups :: TypeRepMap (Proxy :: Nat -> *)
39 -> ( Proxy 1000, Proxy 2000, Proxy 3000, Proxy 4000
40 , Proxy 5000, Proxy 6000, Proxy 7000, Proxy 8000
42tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
44 lp :: forall (a::Nat). Typeable a => Proxy a
45 lp = fromJust $ lookup tmap
47-- TypeRepMap of 10000 elements
48bigMap :: TypeRepMap (Proxy :: Nat -> *)
49bigMap = buildBigMap 10000 (Proxy :: Proxy 0) empty
51buildBigMap :: forall a . (Typeable a, KnownNat a) => Int -> Proxy (a :: Nat) -> TypeRepMap (Proxy :: Nat -> *) -> TypeRepMap (Proxy :: Nat -> *)
52buildBigMap 1 x = insert x
53buildBigMap n x = insert x . buildBigMap (n - 1) (Proxy :: Proxy (a + 1))
55rknf :: TypeRepMap f -> ()
58prepareBenchMap :: IO ()
59prepareBenchMap = evaluate (rknf bigMap)
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