diff --git a/benchmarks/alongside.hs b/benchmarks/alongside.hs index 200f1f530..ceb66efb9 100644 --- a/benchmarks/alongside.hs +++ b/benchmarks/alongside.hs @@ -70,22 +70,20 @@ half l r pfq (s,s') = fmap (\(b,t') -> (peekContext b x,t')) (getCompose (r (\a' -- alongside' :: Lens s t a b -> Lens s' t' a' b' -> Lens (s,s') (t,t') (a,a') (b,b') -- {-# INLINE alongside'#-} -compound :: Lens s t a b - -> Lens s' t' a' b' - -> Lens (s,s') (t,t') (a,a') (b,b') +compound :: Lens' s a + -> Lens' s' a' + -> Lens' (s,s') (a,a') compound l r = lens (\(s, s') -> (view l s, view r s')) (\(s, s') (t, t') -> (set l t s, set r t' s')) {-# INLINE compound #-} -compound5 :: Lens s t a b - -> Lens s' t' a' b' - -> Lens s'' t'' a'' b'' - -> Lens s''' t''' a''' b''' - -> Lens s'''' t'''' a'''' b'''' - -> Lens (s, (s', (s'', (s''', s'''')))) - (t, (t', (t'', (t''', t'''')))) +compound5 :: Lens' s a + -> Lens' s' a' + -> Lens' s'' a'' + -> Lens' s''' a''' + -> Lens' s'''' a'''' + -> Lens' (s, (s', (s'', (s''', s'''')))) (a, (a', (a'', (a''', a'''')))) - (b, (b', (b'', (b''', b'''')))) compound5 l l' l'' l''' l'''' = lens (\(s, (s', (s'', (s''', s'''')))) -> (view l s, (view l' s', (view l'' s'', (view l''' s''', view l'''' s'''')))) ) diff --git a/benchmarks/plated.hs b/benchmarks/plated.hs index 027a544a1..9d6858e7a 100644 --- a/benchmarks/plated.hs +++ b/benchmarks/plated.hs @@ -2,7 +2,15 @@ {-# LANGUAGE Rank2Types #-} {-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-} {-# OPTIONS_GHC -funbox-strict-fields #-} + +#ifndef MIN_VERSION_base +#define MIN_VERSION_base(x,y,z) 1 +#endif + +#if !(MIN_VERSION_base(4,8,0)) import Control.Applicative +#endif + import Control.Lens import Control.DeepSeq import Criterion.Main diff --git a/benchmarks/unsafe.hs b/benchmarks/unsafe.hs index 8837be3de..b70e5880a 100644 --- a/benchmarks/unsafe.hs +++ b/benchmarks/unsafe.hs @@ -6,16 +6,18 @@ import Control.Lens.Internal import Control.Exception import Criterion.Main -import Criterion.Config +import Criterion.Types (Config(..)) + +import Data.Functor.Identity (Identity(..)) import GHC.Exts overS :: ASetter s t a b -> (a -> b) -> s -> t -overS l f = runMutator . l (Mutator . f) +overS l f = runIdentity . l (Identity . f) {-# INLINE overS #-} mappedS :: ASetter [a] [b] a b -mappedS f = Mutator . map (runMutator . f) +mappedS f = Identity . map (runIdentity . f) {-# INLINE mappedS #-} overU :: ASetter s t a b -> (a -> b) -> s -> t @@ -53,11 +55,11 @@ main = do --l = replicate n (); f = (\ _ -> ()) --l = replicate n (); f = (\ !_ -> ()) -- strange results --l = replicate n (); f = lazy (\_ -> ()) - defaultMainWith config (return ()) + defaultMainWith config [ bench "map safe noinline" $ nf (mapSN f) l , bench "map safe inline" $ nf (mapSI f) l , bench "map unsafe noinline" $ nf (mapUN f) l , bench "map unsafe inline" $ nf (mapUI f) l ] where - config = defaultConfig { cfgSamples = ljust 1000 } + config = defaultConfig { resamples = 1000 } diff --git a/benchmarks/zipper.hs b/benchmarks/zipper.hs deleted file mode 100644 index 44dbd44d3..000000000 --- a/benchmarks/zipper.hs +++ /dev/null @@ -1,45 +0,0 @@ -module Main - ( main -- :: IO () - ) where - -import Control.Lens -import Criterion.Main - -main :: IO () -main = defaultMain - [ bgroup "rezip" - [ bench "rezip" $ nf tugAndRezip1 ['a'..'z'] - , bench "farthest leftward" $ nf tugAndRezip2 ['a'..'z'] - , bench "leftmost" $ nf tugAndRezip3 ['a'..'z'] - , bench "tugTo" $ nf tugAndRezip4 ['a'..'z'] - ] - , bgroup "zipper creation" - [ bench "over traverse id" $ nf (over traverse id) ['a'..'z'] - , bench "zipper" $ nf zipTraverseRezip ['a'..'z'] - ] - , bgroup "downward" - [ bench "downward _1" $ nf downwardAndRezip1 (['a'..'z'],['z'..'a']) - , bench "fromWithin" $ nf downwardAndRezip2 (['a'..'z'],['z'..'a']) - ] - ] - --- What's the fastest rezip of all? -tugAndRezip1, tugAndRezip2, tugAndRezip3 :: String -> String -tugAndRezip1 xs = zipntugs 25 xs & focus .~ 'a' & rezip -tugAndRezip2 xs = zipntugs 25 xs & focus .~ 'b' & farthest leftward & rezip -tugAndRezip3 xs = zipntugs 25 xs & focus .~ 'c' & leftmost & rezip -tugAndRezip4 xs = zipntugs 25 xs & focus .~ 'd' & tugTo 0 & rezip - -zipntugs i x = zipper x & fromWithin traverse & tugs rightward i - --- How fast is creating and destroying a zipper compared to --- a regular traversal? -zipTraverseRezip x = zipper x & fromWithin traverse & rezip - --- is 'downward' any faster than the composition of traverse? -downwardAndRezip1 :: (String, String) -> (String, String) -downwardAndRezip1 xs = - zipper xs & downward _1 & fromWithin traverse & focus .~ 'h' & rezip -downwardAndRezip2 :: (String, String) -> (String, String) -downwardAndRezip2 xs = - zipper xs & fromWithin (_1.traverse) & focus .~ 'g' & rezip diff --git a/lens.cabal b/lens.cabal index 423c3222a..656e023a4 100644 --- a/lens.cabal +++ b/lens.cabal @@ -452,8 +452,7 @@ benchmark alongside hs-source-dirs: benchmarks build-depends: base, - comonad, - comonads-fd, + comonad >= 4, criterion, deepseq, lens, @@ -497,25 +496,8 @@ benchmark unsafe hs-source-dirs: benchmarks build-depends: base, - comonad, - comonads-fd, - criterion, - deepseq, - generic-deriving, - lens, - transformers - --- Benchmarking zipper usage -benchmark zipper - type: exitcode-stdio-1.0 - main-is: zipper.hs - ghc-options: -w -O2 -threaded -fdicts-cheap -funbox-strict-fields - hs-source-dirs: benchmarks - build-depends: - base, - comonad, - comonads-fd, - criterion, + comonad >= 4, + criterion >= 1, deepseq, generic-deriving, lens,