1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE NamedFieldPuns #-}
4{-# LANGUAGE RankNTypes #-}
5{-# LANGUAGE RecordWildCards #-}
6{-# LANGUAGE TypeApplications #-}
8module Main (main) where
11import Control.Lens.Operators
12import Control.Lens.Type
15import Data.Generics.Product
21 [ env (arbitraryAnimalsOfLength 100) $ products 100
22 , env (arbitraryAnimalsOfLength 1000) $ products 1000
23 , env (arbitraryAnimalsOfLength 10000) $ products 10000
24 , env (arbitraryAnimalsOfLength 100000) $ products 100000
27products :: Int -> [Animal] -> Benchmark
29 = bgroup ("products/" ++ show n)
30 [ bench "generic-lens/get" (nf (const $ map (^. field @"name") as) ())
31 , bench "lens/get" (nf (const $ map (^. aName) as) ())
32 , bench "generic-lens/set" (nf (const $ map (\a -> a & field @"name" .~ "Name") as) ())
33 , bench "lens/set" (nf (const $ map (\a -> a & aName .~ "Name") as) ())
36arbitraryAnimalsOfLength :: Int -> IO [Animal]
37arbitraryAnimalsOfLength n
38 = replicateM n (generate arbitrary)
44 } deriving (Generic, Show)
46instance Arbitrary Animal where
47 arbitrary = Animal <$> arbitrary <*> arbitrary <*> arbitrary
49instance NFData Animal where
50 rnf Animal{..} = rnf name `seq` rnf age `seq` rnf eats
52aName :: Lens' Animal String
54 = (\x -> Animal { name = x, age, eats }) <$> f name
57aAge :: Lens' Animal Int
59 = (\x -> Animal { name, age = x, eats }) <$> f age
61aEats :: Lens' Animal String
63 = (\x -> Animal { name, age, eats = x }) <$> f eats
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