1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE ExplicitNamespaces #-}
3{-# LANGUAGE KindSignatures #-}
4{-# LANGUAGE PolyKinds #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE TypeFamilies #-}
7{-# LANGUAGE TypeOperators #-}
8{-# LANGUAGE UndecidableInstances #-}
10{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
16import Criterion.Main (Benchmark, bench, bgroup, nf)
18import Prelude hiding (lookup)
20import Data.Maybe (fromJust)
21import Data.Proxy (Proxy (..))
22import Data.Typeable (Typeable)
25import Data.TypeRep.OptimalVector
27benchVectorOpt :: Benchmark
28benchVectorOpt = bgroup "vector optimal"
29 [ bench "lookup" $ nf tenLookups bigMap
30 -- , bench "insert new" $ whnf (\x -> rknf $ insert x bigMap) (Proxy :: Proxy 9999999999)
31 -- , bench "update old" $ whnf (\x -> rknf $ insert x bigMap) (Proxy :: Proxy 1)
34tenLookups :: TypeRepVector (Proxy :: Nat -> *)
35 -> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
36 , Proxy 50, Proxy 60, Proxy 70, Proxy 80
38tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
40 lp :: forall (a::Nat). Typeable a => Proxy a
41 lp = fromJust $ lookup tmap
43-- TypeRepMap of 10000 elements
44bigMap :: TypeRepVector (Proxy :: Nat -> *)
45bigMap = fromList $ buildBigMap 10000 (Proxy :: Proxy 0) []
50buildBigMap :: forall a . (Typeable a, KnownNat a) => Int -> Proxy (a :: Nat) -> [TF (Proxy :: Nat -> *)] -> [TF (Proxy :: Nat -> *)]
51buildBigMap 1 x = (TF x :)
52buildBigMap n x = (TF x :) . buildBigMap (n - 1) (Proxy :: Proxy (a + 1))
54-- rknf :: TypeRepMap f -> ()
57type family BigProxy (n :: Nat) :: * where
59 BigProxy n = S (BigProxy (n - 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