From fe9fd056297a64f8d6bd22f964b66aff90adb1a7 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Fri, 7 Apr 2023 21:29:05 -0700 Subject: [PATCH 01/13] yampa: Enable expose-core flag. Refs #269. Re-introduce flag expose-core to control whether the module FRP.Yampa.InternalCore should be exposed. This reverts commit e61e07e50fd513b68eb1d462e8494ac9eb565a04. --- yampa/Yampa.cabal | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/yampa/Yampa.cabal b/yampa/Yampa.cabal index 7ac7d6dd..a6e36cfe 100644 --- a/yampa/Yampa.cabal +++ b/yampa/Yampa.cabal @@ -72,6 +72,24 @@ flag examples default: False manual: True +-- WARNING: The following flag exposes Yampa's core. You should avoid using +-- this at all. The only reason to expose it is that we are using Yampa for +-- research, and many extensions require that we expose the constructors. No +-- released project should depend on this. In general, you should always +-- install Yampa with this flag disabled. +flag expose-core + description: + You can enable exposing some of Yampa's core constructs using + -fexpose-core. + . + Enabling this is an unsupported configuration, but it may be useful if you + are building an extension of Yampa for research and do not wish to fork + Yampa completely. + . + No released project should ever depend on this. + default: False + manual: True + library exposed-modules: @@ -95,7 +113,6 @@ library other-modules: -- Auxiliary (commonly used) types FRP.Yampa.Diagnostics - FRP.Yampa.InternalCore build-depends: base < 6 @@ -117,6 +134,14 @@ library build-depends: fail == 4.9.* + if flag(expose-core) + exposed-modules: + FRP.Yampa.InternalCore + else + other-modules: + FRP.Yampa.InternalCore + + test-suite hlint type: exitcode-stdio-1.0 From afa55545e4513280a13bb69dbba9c8ed4229153e Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Sun, 30 Aug 2020 07:21:46 -0400 Subject: [PATCH 02/13] yampa: Introduce benchmark. Refs #167. This commit implements a basic benchmark that is integrated in the Yampa package. The goal is to have an initial benchmark infrastructure that can be used to evaluate the performance of Yampa, and compare between different versions, and to make evidence-based decisions about when new features should be incorporated into Yampa. --- yampa/Yampa.cabal | 20 +++++ yampa/benchmarks/Bench.hs | 155 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 yampa/benchmarks/Bench.hs diff --git a/yampa/Yampa.cabal b/yampa/Yampa.cabal index a6e36cfe..d83a30f2 100644 --- a/yampa/Yampa.cabal +++ b/yampa/Yampa.cabal @@ -340,3 +340,23 @@ executable yampa-examples-tailgatingdetector else buildable: False + +benchmark yampa-bench + type: + exitcode-stdio-1.0 + + main-is: + Bench.hs + + build-depends: + base + , criterion + , filepath + , time + , Yampa + + default-language: + Haskell2010 + + hs-source-dirs: + benchmarks diff --git a/yampa/benchmarks/Bench.hs b/yampa/benchmarks/Bench.hs new file mode 100644 index 00000000..25aa54a0 --- /dev/null +++ b/yampa/benchmarks/Bench.hs @@ -0,0 +1,155 @@ +-- | +-- Description : A benchmark for Yampa. +-- Copyright : (c) Ivan Perez, 2023 +-- Authors : Ivan Perez +-- +-- A benchmark for Yampa. +module Main where + +import Criterion (bench, bgroup, nf) +import Criterion.Main (defaultConfig, defaultMainWith) +import Criterion.Types (Config(csvFile, resamples, verbosity) + , Verbosity(Quiet)) +import Data.Time.LocalTime (getZonedTime) +import Data.Time.Format (formatTime, defaultTimeLocale) +import System.Environment (getArgs, withArgs) +import System.FilePath (()) + +import FRP.Yampa + +-- | 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 + +-- | Yampa's specialized identity function. +basicIdentity :: Int -> [Int] +basicIdentity n = embed sf stream + where + sf = identity + stream = deltaEncode 1.0 (replicate n 1) + +-- | Standard function identity lifted to SFs. +basicId :: Int -> [Int] +basicId n = embed sf stream + where + sf = arr id + stream = deltaEncode 1.0 (replicate n 1) + +-- ** Compositions + +-- | Composition of Yampa's specialized identity function. +composeIdentity :: Int -> [Int] +composeIdentity n = embed sf stream + where + sf = identity >>> identity + stream = deltaEncode 1.0 (replicate n 1) + +-- | Composition of standard function identity lifted to SFs. +composeIdId :: Int -> [Int] +composeIdId n = embed sf stream + where + sf = arr id >>> arr id + stream = deltaEncode 1.0 (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 = embed sf stream + where + sf = arr (+3) + stream = deltaEncode 1.0 $ take n [1..] + +-- | Composition of addition lifted to SFs. +composePlusPlus :: Int -> [Int] +composePlusPlus n = embed sf stream + where + sf = arr (+1) >>> arr (+2) + stream = deltaEncode 1.0 $ take n [1..] + +-- | Composition of addition with multiplication, lifted to SFs. +composePlusMult :: Int -> [Int] +composePlusMult n = embed sf stream + where + sf = arr (+100) >>> arr (*2) + stream = deltaEncode 1.0 $ 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 = embed sf stream + where + sf = arr (*20) + stream = deltaEncode 1.0 $ take n [10..] + +-- | Composition of multiplication lifted to SFs. +composeMultMult :: Int -> [Int] +composeMultMult n = embed sf stream + where + sf = arr (*10) >>> arr (*2) + stream = deltaEncode 1.0 $ take n [10..] + +-- ** Counter + +-- | Counter without explicit seq. +counter1 :: Int -> [Int] +counter1 n = embed sf stream + where + sf = loopPre 0 (arr (dup . uncurry (+))) + stream = deltaEncode 1.0 (replicate n 1) + +-- | Counter with explicit seq. +counter2 :: Int -> [Int] +counter2 n = embed sf stream + where + sf = loopPre 0 (arr ((\x -> x `seq` (x, x)). uncurry (+))) + stream = deltaEncode 1.0 (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 + } From 286aa3571b7338d5afa02b92995b7b0709037ce8 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Mon, 7 Aug 2023 15:29:25 +0000 Subject: [PATCH 03/13] yampa: Document existence of benchmarks in README. Refs #167. Benchmarks are useless unless people actually use them to evaluate their proposed solutions. This commit modifies the README to document the existence of benchmarks already as part of the Yampa package. --- yampa/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yampa/README.md b/yampa/README.md index ea9c6ec3..5eb4b0b1 100644 --- a/yampa/README.md +++ b/yampa/README.md @@ -431,6 +431,10 @@ This project is split in two: Yampa's unit tests are mostly implemented as tests inside the yampa-test library. The module hierarchy of `yampa-test/tests/Test` mirrors that of Yampa. +Yampa also includes some benchmarks as part of the main library. You are +encouraged to use them to evaluate your pull requests, and to improve the +benchmarks themselves. + A directory `yampa/examples` contains a number of examples of Yampa programs, some of which can be installed with the flag `-fexamples`. From 6b5372fc3f803b1a26ad0edcac7c2834921fa436 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Mon, 7 Aug 2023 15:31:47 +0000 Subject: [PATCH 04/13] yampa: Document changes in CHANGELOG. Refs #167. --- yampa/CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yampa/CHANGELOG b/yampa/CHANGELOG index 49e3cc6c..3d244586 100644 --- a/yampa/CHANGELOG +++ b/yampa/CHANGELOG @@ -1,3 +1,6 @@ +2023-08-07 Ivan Perez + * Introduce benchmark (#167). + 2023-06-07 Ivan Perez * Version bump (0.14.3) (#269). * Improve readability of CHANGELOGs (#261). From 0421f380350acb6c5dc715bf7f57881ff669d006 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 02:30:28 +0000 Subject: [PATCH 05/13] yampa: Add version bounds to dependencies. Refs #273. The Yampa package does not specify version bounds for all its dependencies. This makes dependency resolution harder, and opens the door to installation plans that may not work out. This commit gives versions bounds for all dependencies of all targets in the Yampa package. --- yampa/Yampa.cabal | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yampa/Yampa.cabal b/yampa/Yampa.cabal index d83a30f2..507d7b90 100644 --- a/yampa/Yampa.cabal +++ b/yampa/Yampa.cabal @@ -349,10 +349,10 @@ benchmark yampa-bench Bench.hs build-depends: - base - , criterion - , filepath - , time + base < 5 + , criterion >= 0.5.0.0 && < 1.7 + , filepath >= 1.3.0.1 && < 1.5 + , time >= 1.4 && < 1.13 , Yampa default-language: From bdbb716bc1dd56bbf124ccb48818c6e3b6f32545 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 02:48:00 +0000 Subject: [PATCH 06/13] yampa-test: Add version bounds to dependencies. Refs #273. The yampa-test package does not specify version bounds for all its dependencies. This makes dependency resolution harder, and opens the door to installation plans that may not work out. This commit gives version bounds for all dependencies of all targets in the yampa-test package. --- yampa-test/yampa-test.cabal | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/yampa-test/yampa-test.cabal b/yampa-test/yampa-test.cabal index 30cf737b..0358c370 100644 --- a/yampa-test/yampa-test.cabal +++ b/yampa-test/yampa-test.cabal @@ -81,10 +81,10 @@ library FRP.Yampa.Stream build-depends: - base >= 4 && < 5 - , normaldistribution - , QuickCheck - , Yampa >= 0.14.3 && < 0.15 + base >= 4 && < 5 + , normaldistribution >= 1.1.0.1 && < 1.2 + , QuickCheck >= 2.12 && < 2.15 + , Yampa >= 0.14.3 && < 0.15 default-language: Haskell2010 @@ -121,11 +121,11 @@ test-suite yampa-quicheck build-depends: base < 5 - , Cabal >= 1.19 - , QuickCheck - , random - , tasty - , tasty-quickcheck + , Cabal >= 1.19 && < 3.9 + , QuickCheck >= 2.12 && < 2.15 + , random >= 1.1 && < 1.3 + , tasty >= 0.1 && < 1.5 + , tasty-quickcheck >= 0.1 && < 0.11 , Yampa , yampa-test From c81c1b34071b56258752d320d2d2fb1b9c32b8c4 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 02:51:16 +0000 Subject: [PATCH 07/13] yampa: Document changes in CHANGELOG. Refs #273. --- yampa/CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/yampa/CHANGELOG b/yampa/CHANGELOG index 3d244586..35f17633 100644 --- a/yampa/CHANGELOG +++ b/yampa/CHANGELOG @@ -1,5 +1,6 @@ 2023-08-07 Ivan Perez * Introduce benchmark (#167). + * Add version bounds to dependencies (#273). 2023-06-07 Ivan Perez * Version bump (0.14.3) (#269). From 62fb956bdd71826adb0038f51bf76e55454ebb2a Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 02:51:22 +0000 Subject: [PATCH 08/13] yampa-test: Document changes in CHANGELOG. Refs #273. --- yampa-test/CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yampa-test/CHANGELOG b/yampa-test/CHANGELOG index 4b0e16ff..f3af114c 100644 --- a/yampa-test/CHANGELOG +++ b/yampa-test/CHANGELOG @@ -1,3 +1,6 @@ +2023-08-07 Ivan Perez + * Add version bounds to dependencies (#273). + 2023-06-07 Ivan Perez * Version bump (0.14.3) (#269). * Improve readability of CHANGELOGs (#261). From bc713440e3ee2a20cdbf5b94fb5156378e29fa7b Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Sat, 8 Apr 2023 04:00:23 +0000 Subject: [PATCH 09/13] yampa: Disable flag before release. Refs #274. The internal-core flag exposes Yampa's internals. This kind of facility is discouraged by hackage. This commit removes that flag altogether before the upload to hackage. --- yampa/Yampa.cabal | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/yampa/Yampa.cabal b/yampa/Yampa.cabal index 507d7b90..96eaa624 100644 --- a/yampa/Yampa.cabal +++ b/yampa/Yampa.cabal @@ -72,24 +72,6 @@ flag examples default: False manual: True --- WARNING: The following flag exposes Yampa's core. You should avoid using --- this at all. The only reason to expose it is that we are using Yampa for --- research, and many extensions require that we expose the constructors. No --- released project should depend on this. In general, you should always --- install Yampa with this flag disabled. -flag expose-core - description: - You can enable exposing some of Yampa's core constructs using - -fexpose-core. - . - Enabling this is an unsupported configuration, but it may be useful if you - are building an extension of Yampa for research and do not wish to fork - Yampa completely. - . - No released project should ever depend on this. - default: False - manual: True - library exposed-modules: @@ -113,6 +95,7 @@ library other-modules: -- Auxiliary (commonly used) types FRP.Yampa.Diagnostics + FRP.Yampa.InternalCore build-depends: base < 6 @@ -134,14 +117,6 @@ library build-depends: fail == 4.9.* - if flag(expose-core) - exposed-modules: - FRP.Yampa.InternalCore - else - other-modules: - FRP.Yampa.InternalCore - - test-suite hlint type: exitcode-stdio-1.0 From eb33580c9b9f679d31f57f3373fc055f982bea15 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 03:12:54 +0000 Subject: [PATCH 10/13] yampa: Version bump (0.14.4). Refs #274. --- yampa/Yampa.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yampa/Yampa.cabal b/yampa/Yampa.cabal index 96eaa624..ddb48b2f 100644 --- a/yampa/Yampa.cabal +++ b/yampa/Yampa.cabal @@ -30,7 +30,7 @@ cabal-version: >= 1.10 build-type: Simple name: Yampa -version: 0.14.3 +version: 0.14.4 author: Henrik Nilsson, Antony Courtney maintainer: Ivan Perez (ivan.perez@keera.co.uk) homepage: https://github.com/ivanperez-keera/Yampa/ From a0a36c057aa827d9960578f308b726edd68fe9e7 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 03:13:17 +0000 Subject: [PATCH 11/13] yampa-test: Version bump (0.14.4). Refs #274. --- yampa-test/yampa-test.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yampa-test/yampa-test.cabal b/yampa-test/yampa-test.cabal index 0358c370..4642a8c6 100644 --- a/yampa-test/yampa-test.cabal +++ b/yampa-test/yampa-test.cabal @@ -31,7 +31,7 @@ cabal-version: >= 1.10 build-type: Simple name: yampa-test -version: 0.14.3 +version: 0.14.4 author: Ivan Perez maintainer: ivan.perez@keera.co.uk homepage: http://github.com/ivanperez-keera/Yampa @@ -84,7 +84,7 @@ library base >= 4 && < 5 , normaldistribution >= 1.1.0.1 && < 1.2 , QuickCheck >= 2.12 && < 2.15 - , Yampa >= 0.14.3 && < 0.15 + , Yampa >= 0.14.4 && < 0.15 default-language: Haskell2010 From a079f933cfe4490b8966e947803a8c3f6c74cc3c Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 03:13:39 +0000 Subject: [PATCH 12/13] yampa: Document changes in CHANGELOG. Refs #274. --- yampa/CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/yampa/CHANGELOG b/yampa/CHANGELOG index 35f17633..9698211a 100644 --- a/yampa/CHANGELOG +++ b/yampa/CHANGELOG @@ -1,4 +1,5 @@ 2023-08-07 Ivan Perez + * Version bump (0.14.4) (#274). * Introduce benchmark (#167). * Add version bounds to dependencies (#273). From 2c5362f4c6fee1ff47aef2efd26bcb5caedbdc9d Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 8 Aug 2023 03:13:56 +0000 Subject: [PATCH 13/13] yampa-test: Document changes in CHANGELOG. Refs #274. --- yampa-test/CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/yampa-test/CHANGELOG b/yampa-test/CHANGELOG index f3af114c..562252af 100644 --- a/yampa-test/CHANGELOG +++ b/yampa-test/CHANGELOG @@ -1,4 +1,5 @@ 2023-08-07 Ivan Perez + * Version bump (0.14.4) (#274). * Add version bounds to dependencies (#273). 2023-06-07 Ivan Perez