-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
14 changed files
with
321 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,77 @@ | ||
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} | ||
|
||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE ExplicitNamespaces #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} | ||
|
||
module CMap | ||
( spec | ||
) where | ||
|
||
import Criterion.Main (bench, nf, env, whnf) | ||
( spec | ||
) where | ||
|
||
import Prelude hiding (lookup) | ||
|
||
import Spec | ||
import Criterion.Main (bench, env, nf, whnf) | ||
import Data.Kind (Type) | ||
import Data.Maybe (fromJust) | ||
import Data.Proxy (Proxy (..)) | ||
import Data.Typeable (Typeable) | ||
import GHC.TypeLits | ||
import GHC.TypeLits (type (+), KnownNat, Nat) | ||
|
||
import Data.TypeRep.CMap (TypeRepMap (..), empty, insert, lookup) | ||
|
||
import Spec (BenchSpec (..)) | ||
|
||
|
||
spec :: BenchSpec | ||
spec = BenchSpec | ||
{ benchLookup = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ nf tenLookups bigMap | ||
, benchInsertSmall = Just $ \name -> | ||
bench name $ whnf (inserts empty 10) (Proxy @ 99999) | ||
, benchInsertBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~(bigMap) -> | ||
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999) | ||
, benchUpdateSmall = Just $ \name -> | ||
env (mkMap 10) $ \ ~(smallMap) -> | ||
bench name $ whnf (inserts smallMap 10) (Proxy @ 0) | ||
, benchUpdateBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~(bigMap) -> | ||
bench name $ whnf (inserts bigMap 10) (Proxy @ 0) | ||
} | ||
{ benchLookup = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ nf tenLookups bigMap | ||
, benchInsertSmall = Just $ \name -> | ||
bench name $ whnf (inserts empty 10) (Proxy @ 99999) | ||
, benchInsertBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999) | ||
, benchUpdateSmall = Just $ \name -> | ||
env (mkMap 10) $ \ ~smallMap -> | ||
bench name $ whnf (inserts smallMap 10) (Proxy @ 0) | ||
, benchUpdateBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ whnf (inserts bigMap 10) (Proxy @ 0) | ||
} | ||
|
||
tenLookups :: TypeRepMap (Proxy :: Nat -> *) | ||
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40 | ||
, Proxy 50, Proxy 60, Proxy 70, Proxy 80 | ||
) | ||
tenLookups | ||
:: TypeRepMap (Proxy :: Nat -> Type) | ||
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40 | ||
, Proxy 50, Proxy 60, Proxy 70, Proxy 80 | ||
) | ||
tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp) | ||
where | ||
lp :: forall (a::Nat). Typeable a => Proxy a | ||
lp = fromJust $ lookup tmap | ||
|
||
inserts :: forall a . (KnownNat a) | ||
=> TypeRepMap (Proxy :: Nat -> *) | ||
-> Int | ||
-> Proxy (a :: Nat) | ||
-> TypeRepMap (Proxy :: Nat -> *) | ||
inserts | ||
:: forall a . (KnownNat a) | ||
=> TypeRepMap (Proxy :: Nat -> Type) | ||
-> Int | ||
-> Proxy (a :: Nat) | ||
-> TypeRepMap (Proxy :: Nat -> Type) | ||
inserts !c 0 _ = c | ||
inserts !c n x = inserts | ||
(insert x c) | ||
(n-1) | ||
(Proxy :: Proxy (a+1)) | ||
(insert x c) | ||
(n-1) | ||
(Proxy :: Proxy (a+1)) | ||
|
||
mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> *)) | ||
mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> Type)) | ||
mkMap n = pure $ buildBigMap n (Proxy :: Proxy 0) empty | ||
|
||
buildBigMap :: forall a . (KnownNat a) => Int -> Proxy (a :: Nat) -> TypeRepMap (Proxy :: Nat -> *) -> TypeRepMap (Proxy :: Nat -> *) | ||
buildBigMap | ||
:: forall a . (KnownNat a) | ||
=> Int | ||
-> Proxy (a :: Nat) | ||
-> TypeRepMap (Proxy :: Nat -> Type) | ||
-> TypeRepMap (Proxy :: Nat -> Type) | ||
buildBigMap 1 x = insert x | ||
buildBigMap n x = insert x . buildBigMap (n - 1) (Proxy :: Proxy (a + 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,79 @@ | ||
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} | ||
|
||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE ExplicitNamespaces #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} | ||
|
||
module CacheMap | ||
( spec | ||
) where | ||
|
||
import Criterion.Main (bench, nf, whnf, env) | ||
import Spec | ||
( spec | ||
) where | ||
|
||
import Prelude hiding (lookup) | ||
|
||
import Criterion.Main (bench, env, nf, whnf) | ||
import Data.Kind (Type) | ||
import Data.Maybe (fromJust) | ||
import Data.Proxy (Proxy (..)) | ||
import Data.Typeable (Typeable) | ||
import GHC.Exts (fromList) | ||
import GHC.TypeLits | ||
import GHC.TypeLits (type (+), KnownNat, Nat) | ||
|
||
import Data.TypeRepMap.Internal (TypeRepMap (..), WrapTypeable (..), empty, insert, lookup) | ||
|
||
import Spec (BenchSpec (..)) | ||
|
||
import Data.TypeRepMap.Internal (TypeRepMap (..), WrapTypeable (..), lookup, insert, empty) | ||
|
||
spec :: BenchSpec | ||
spec = BenchSpec | ||
{ benchLookup = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ nf tenLookups bigMap | ||
, benchInsertSmall = Just $ \name -> | ||
bench name $ whnf (inserts empty 10) (Proxy @ 99999) | ||
, benchInsertBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~(bigMap) -> | ||
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999) | ||
, benchUpdateSmall = Just $ \name -> | ||
env (mkMap 10) $ \ ~(smallMap) -> | ||
bench name $ whnf (inserts smallMap 10) (Proxy @ 0) | ||
, benchUpdateBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~(bigMap) -> | ||
bench name $ whnf (inserts bigMap 10) (Proxy @ 0) | ||
} | ||
{ benchLookup = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ nf tenLookups bigMap | ||
, benchInsertSmall = Just $ \name -> | ||
bench name $ whnf (inserts empty 10) (Proxy @ 99999) | ||
, benchInsertBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999) | ||
, benchUpdateSmall = Just $ \name -> | ||
env (mkMap 10) $ \ ~smallMap -> | ||
bench name $ whnf (inserts smallMap 10) (Proxy @ 0) | ||
, benchUpdateBig = Just $ \name -> | ||
env (mkMap 10000) $ \ ~bigMap -> | ||
bench name $ whnf (inserts bigMap 10) (Proxy @ 0) | ||
} | ||
|
||
tenLookups :: TypeRepMap (Proxy :: Nat -> *) | ||
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40 | ||
, Proxy 50, Proxy 60, Proxy 70, Proxy 80 | ||
) | ||
tenLookups | ||
:: TypeRepMap (Proxy :: Nat -> Type) | ||
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40 | ||
, Proxy 50, Proxy 60, Proxy 70, Proxy 80 | ||
) | ||
tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp) | ||
where | ||
lp :: forall (a::Nat). Typeable a => Proxy a | ||
lp :: forall (a :: Nat) . Typeable a => Proxy a | ||
lp = fromJust $ lookup tmap | ||
|
||
inserts :: forall a . (KnownNat a) | ||
=> TypeRepMap (Proxy :: Nat -> *) | ||
-> Int | ||
-> Proxy (a :: Nat) | ||
-> TypeRepMap (Proxy :: Nat -> *) | ||
inserts | ||
:: forall a . (KnownNat a) | ||
=> TypeRepMap (Proxy :: Nat -> Type) | ||
-> Int | ||
-> Proxy (a :: Nat) | ||
-> TypeRepMap (Proxy :: Nat -> Type) | ||
inserts !c 0 _ = c | ||
inserts !c n x = inserts | ||
(insert x c) | ||
(n-1) | ||
(Proxy :: Proxy (a+1)) | ||
(insert x c) | ||
(n-1) | ||
(Proxy :: Proxy (a + 1)) | ||
|
||
mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> *)) | ||
mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> Type)) | ||
mkMap n = pure $ fromList $ buildBigMap n (Proxy :: Proxy 0) [] | ||
|
||
|
||
buildBigMap :: forall a . (KnownNat a) | ||
=> Int | ||
-> Proxy (a :: Nat) | ||
-> [WrapTypeable (Proxy :: Nat -> *)] | ||
-> [WrapTypeable (Proxy :: Nat -> *)] | ||
buildBigMap | ||
:: forall a . (KnownNat a) | ||
=> Int | ||
-> Proxy (a :: Nat) | ||
-> [WrapTypeable (Proxy :: Nat -> Type)] | ||
-> [WrapTypeable (Proxy :: Nat -> Type)] | ||
buildBigMap 1 x = (WrapTypeable x :) | ||
buildBigMap n x = (WrapTypeable x :) . buildBigMap (n - 1) (Proxy :: Proxy (a + 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.