dunai 0.11.1 → 0.11.2
raw patch · 3 files changed
+188/−1 lines, 3 filesdep +criteriondep +timedep ~basedep ~filepathPVP ok
version bump matches the API change (PVP)
Dependencies added: criterion, time
Dependency ranges changed: base, filepath
API changes (from Hackage documentation)
Files
- CHANGELOG +4/−0
- benchmarks/Bench.hs +162/−0
- dunai.cabal +22/−1
CHANGELOG view
@@ -1,3 +1,7 @@+2023-08-21 Ivan Perez <ivan.perez@keera.co.uk>+ * Version bump (0.11.2) (#377).+ * Introduce benchmark (#375).+ 2023-06-21 Ivan Perez <ivan.perez@keera.co.uk> * Version bump (0.11.1) (#372). * Reflect new contribution process in README (#362).
+ benchmarks/Bench.hs view
@@ -0,0 +1,162 @@+-- |+-- Description : A benchmark for dunai.+-- Copyright : (c) Ivan Perez, 2023+-- Authors : Ivan Perez+-- Maintainer : ivan.perez@keera.co.uk+-- License : BSD3+--+-- A benchmark for Dunai.+module Main where++import Criterion (bench, bgroup, nf)+import Criterion.Main (defaultConfig, defaultMainWith)+import Criterion.Types (Config (csvFile, resamples, verbosity),+ Verbosity (Quiet))+import Data.Functor.Identity (runIdentity)+import Data.Time.Format (defaultTimeLocale, formatTime)+import Data.Time.LocalTime (getZonedTime)+import System.Environment (getArgs, withArgs)+import System.FilePath ((</>))++import qualified Control.Category as C++import Data.MonadicStreamFunction++-- | Run all benchmarks.+main :: IO ()+main = do+ config <- customConfig+ withArgs [] $+ defaultMainWith config+ [ bgroup "basic"+ [ bench "identity" $ nf basicIdentity 10000+ , bench "id" $ nf basicId 10000+ ]+ , bgroup "compositions"+ [ bench "identity" $ nf composeIdentity 10000+ , bench "idid" $ nf composeIdId 10000+ , bench "plus" $ nf composePlus 10000+ , bench "plusplus" $ nf composePlusPlus 10000+ , bench "plusmult" $ nf composePlusMult 10000+ , bench "mult" $ nf composeMult 10000+ , bench "multmult" $ nf composeMultMult 10000+ ]+ , bgroup "counter"+ [ bench "counter1" $ nf counter1 10000+ , bench "counter2" $ nf counter2 10000+ ]+ ]++-- * Benchmarks++-- ** Basic++-- | Dunai's specialized identity function.+basicIdentity :: Int -> [Int]+basicIdentity n = runIdentity $ embed sf stream+ where+ sf = C.id+ stream = replicate n 1++-- | Standard function identity lifted to SFs.+basicId :: Int -> [Int]+basicId n = runIdentity $ embed sf stream+ where+ sf = arr id+ stream = replicate n 1++-- ** Compositions++-- | Composition of Dunai's specialized identity function.+composeIdentity :: Int -> [Int]+composeIdentity n = runIdentity $ embed sf stream+ where+ sf = C.id >>> C.id+ stream = replicate n 1++-- | Composition of standard function identity lifted to SFs.+composeIdId :: Int -> [Int]+composeIdId n = runIdentity $ embed sf stream+ where+ sf = arr id >>> arr id+ stream = replicate n 1++-- | Plus operation.+--+-- This is not a composition; it merely exists to serve as a comparison with+-- composePlusPlus.+composePlus :: Int -> [Int]+composePlus n = runIdentity $ embed sf stream+ where+ sf = arr (+3)+ stream = take n [1..]++-- | Composition of addition lifted to SFs.+composePlusPlus :: Int -> [Int]+composePlusPlus n = runIdentity $ embed sf stream+ where+ sf = arr (+1) >>> arr (+2)+ stream = take n [1..]++-- | Composition of addition with multiplication, lifted to SFs.+composePlusMult :: Int -> [Int]+composePlusMult n = runIdentity $ embed sf stream+ where+ sf = arr (+100) >>> arr (*2)+ stream = take n [10..]++-- | Multiplication operation.+--+-- This is not a composition; it merely exists to serve as a comparison with+-- composeMultMult.+composeMult :: Int -> [Int]+composeMult n = runIdentity $ embed sf stream+ where+ sf = arr (*20)+ stream = take n [10..]++-- | Composition of multiplication lifted to SFs.+composeMultMult :: Int -> [Int]+composeMultMult n = runIdentity $ embed sf stream+ where+ sf = arr (*10) >>> arr (*2)+ stream = take n [10..]++-- ** Counter++-- | Counter without explicit seq.+counter1 :: Int -> [Int]+counter1 n = runIdentity $ embed sf stream+ where+ sf = feedback 0 (arr (dup . uncurry (+)))+ stream = replicate n 1++ dup x = (x, x)++-- | Counter with explicit seq.+counter2 :: Int -> [Int]+counter2 n = runIdentity $ embed sf stream+ where+ sf = feedback 0 (arr ((\x -> x `seq` (x, x)). uncurry (+)))+ stream = replicate n 1++-- * Auxiliary functions++-- Construct a config with increased number of sampling+-- and a custom name for the report.+customConfig :: IO Config+customConfig = do+ args <- getArgs++ let dir = case args of+ [] -> "."+ (x:xs) -> x++ -- Custom filename using the current time+ timeString <- (formatTime defaultTimeLocale "%F-%H%M%S") <$> getZonedTime+ let filename = concat [ timeString, "-", "bench.csv" ]++ return $ defaultConfig { csvFile = Just $ dir </> filename+ , resamples = 100000+ , verbosity = Quiet+ }
dunai.cabal view
@@ -30,7 +30,7 @@ build-type: Simple name: dunai-version: 0.11.1+version: 0.11.2 author: Ivan Perez, Manuel Bärenz maintainer: ivan.perez@keera.co.uk homepage: https://github.com/ivanperez-keera/dunai@@ -217,3 +217,24 @@ , tasty-hunit , dunai+++benchmark dunai-bench+ type:+ exitcode-stdio-1.0++ main-is:+ Bench.hs++ build-depends:+ base < 5+ , criterion >= 0.5.0.0 && < 1.7+ , filepath >= 1.3.0.1 && < 1.5+ , time >= 1.4 && < 1.13+ , dunai++ default-language:+ Haskell2010++ hs-source-dirs:+ benchmarks