From edce964e31a9a8ddb29ac992bc8d3640c5f5f7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 10 Apr 2024 16:08:29 +0200 Subject: [PATCH] Add free SN wordcount benchmark (slightly slower) --- rhine/bench/WordCount.hs | 15 +++++++++++++++ rhine/rhine.cabal | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/rhine/bench/WordCount.hs b/rhine/bench/WordCount.hs index b82bb6b4..2fe2c0a6 100644 --- a/rhine/bench/WordCount.hs +++ b/rhine/bench/WordCount.hs @@ -28,12 +28,15 @@ import Data.MonadicStreamFunction qualified as Dunai -- rhine import Control.Monad.Trans.MSF.Except qualified as Dunai +import Data.Profunctor (Profunctor (lmap)) import FRP.Rhine import FRP.Rhine.Clock.Except ( DelayIOError, ExceptClock (..), delayIOError, ) +import FRP.Rhine.Rhine.Free qualified as Free +import FRP.Rhine.SN.Free (At (..)) import Paths_rhine -- * Top level benchmarks @@ -43,6 +46,7 @@ benchmarks = bgroup "WordCount" [ bench "rhine" $ nfIO rhineWordCount + , bench "rhine (free sn)" $ nfIO rhineFreeWordCount , bench "dunai" $ nfIO dunaiWordCount , bgroup "Text" @@ -85,6 +89,17 @@ rhineWordCount = do words <- mappendS -< either (const 0) (Sum . length . words) lineOrStop throwOn' -< (either isEOFError (const False) lineOrStop, Right $ getSum words) +rhineFreeWordCount :: IO Int +rhineFreeWordCount = do + Left (Right count) <- withInput $ runExceptT $ Free.flow $ lmap Present $ wc Free.@@ wordCountClock + return count + where + wc :: ClSF (ExceptT (Either IOError Int) IO) WordCountClock () () + wc = proc _ -> do + lineOrStop <- tagS -< () + words <- mappendS -< either (const 0) (Sum . length . words) lineOrStop + throwOn' -< (either isEOFError (const False) lineOrStop, Right $ getSum words) + {- | Idiomatic dunai implementation. Compared to Rhine, this doesn't have the overhead of clocks and exception handling. diff --git a/rhine/rhine.cabal b/rhine/rhine.cabal index fdf0ee5a..adde6e43 100644 --- a/rhine/rhine.cabal +++ b/rhine/rhine.cabal @@ -52,6 +52,7 @@ common opts text >=1.2 && <2.1, transformers >=0.5, vector-sized >=1.4, + profunctors ^>= 5.6.2, if flag(dev) ghc-options: -Werror @@ -151,7 +152,6 @@ library transformers >=0.5, free-category ^>= 0.0.4.5, sop-core ^>= 0.5.0.2, - profunctors ^>= 5.6.2, -- Directories containing source files. hs-source-dirs: src