on main help sign in
typerep-map/benchmark/OptimalVector.hs
60 lines 1.8 kB history raw
1{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
3{-# LANGUAGE DataKinds #-}
4{-# LANGUAGE PolyKinds #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE TypeFamilies #-}
7{-# LANGUAGE TypeOperators #-}
8{-# LANGUAGE UndecidableInstances #-}
10module OptimalVector
11 ( spec
12 ) where
14import Prelude hiding (lookup)
16import Criterion.Main (bench, env, nf)
17import Data.Kind (Type)
18import Data.Maybe (fromJust)
19import Data.Proxy (Proxy (..))
20import Data.Typeable (Typeable)
21import GHC.TypeLits (type (+), KnownNat, Nat)
23import Data.TypeRep.OptimalVector (TF (..), TypeRepMap (..), fromList, lookup)
25import Spec (BenchSpec (..))
28spec :: BenchSpec
29spec = BenchSpec
30 { benchLookup = Just $ \name ->
31 env mkBigMap $ \ ~bigMap ->
32 bench name $ nf tenLookups bigMap
33 , benchInsertSmall = Nothing -- Not implemented
34 , benchInsertBig = Nothing -- Not implemented
35 , benchUpdateSmall = Nothing -- Not implemented
36 , benchUpdateBig = Nothing -- Not implemented
37 }
39tenLookups
40 :: TypeRepMap (Proxy :: Nat -> Type)
41 -> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
42 , Proxy 50, Proxy 60, Proxy 70, Proxy 80
43 )
44tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
45 where
46 lp :: forall (a::Nat). Typeable a => Proxy a
47 lp = fromJust $ lookup tmap
49-- TypeRepMap of 10000 elements
50mkBigMap :: IO (TypeRepMap (Proxy :: Nat -> Type))
51mkBigMap = pure $ fromList $ buildBigMap 10000 (Proxy :: Proxy 0) []
53buildBigMap
54 :: forall a . (KnownNat a)
55 => Int
56 -> Proxy (a :: Nat)
57 -> [TF (Proxy :: Nat -> Type)]
58 -> [TF (Proxy :: Nat -> Type)]
59buildBigMap 1 x = (TF x :)
60buildBigMap n x = (TF x :) . buildBigMap (n - 1) (Proxy :: Proxy (a + 1))