From 63632c927b40e0142e77884cb80ff6a482a13969 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Thu, 27 Jan 2022 22:54:19 +0530 Subject: [PATCH 1/2] Replace functionality of csv with streamly --- bench-show.cabal | 3 +-- lib/BenchShow/Common.hs | 49 +++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/bench-show.cabal b/bench-show.cabal index 0aa7b27..49dcc9e 100644 --- a/bench-show.cabal +++ b/bench-show.cabal @@ -113,7 +113,7 @@ library base >= 4.8 && < 5 , Chart >= 1.6 && < 2 , Chart-diagrams >= 1.6 && < 2 - , csv >= 0.1 && < 0.2 + , streamly >= 0.8 && < 0.9 , filepath >= 1.3 && < 1.5 , mwc-random >= 0.13 && < 0.16 , directory >= 1.2 && < 1.4 @@ -133,7 +133,6 @@ executable bench-show base >= 4.8 && < 4.17 , Chart >= 1.6 && < 2 , Chart-diagrams >= 1.6 && < 2 - , csv >= 0.1 && < 0.2 , filepath >= 1.3 && < 1.5 , mwc-random >= 0.13 && < 0.16 , directory >= 1.2 && < 1.4 diff --git a/lib/BenchShow/Common.hs b/lib/BenchShow/Common.hs index e789f73..48b92ae 100644 --- a/lib/BenchShow/Common.hs +++ b/lib/BenchShow/Common.hs @@ -57,9 +57,15 @@ import Debug.Trace (trace) import Statistics.Types (Estimate(..), ConfInt(..)) import System.Directory (createDirectoryIfMissing) import System.FilePath (()) -import Text.CSV (CSV, parseCSVFromFile) +import System.IO (IOMode(..)) import Text.Read (readMaybe) +import qualified Streamly.Data.Fold as Fold +import qualified Streamly.FileSystem.Handle as Handle +import qualified Streamly.Prelude as Stream +import qualified Streamly.Unicode.Stream as Unicode +import qualified System.IO as IO + import BenchShow.Analysis ------------------------------------------------------------------------------- @@ -81,6 +87,28 @@ filterSanity label old new = do ++ "\nOriginal groups: " ++ show old ++ "\nNew groups: " ++ show new +type CSV = [[String]] + +-- XXX This is ugly in performance but works for the time being. +-- XXX This lib should not depend on internal modules of streamly. +parseCSVFromFile :: FilePath -> IO CSV +parseCSVFromFile inFile = do + src <- IO.openFile inFile ReadMode + + Stream.unfold Handle.read src -- SerialT IO Word8 + & Unicode.decodeUtf8 -- SerialT IO Char + & parseLines -- IO CSV + + where + + parseLine ls = + Stream.toList $ Stream.splitOn (== ',') Fold.toList $ Stream.fromList ls + + parseLines strm = + Stream.splitOn (== '\n') Fold.toList strm + & Stream.mapM parseLine + & Stream.toList + ------------------------------------------------------------------------------- data ReportType = TextReport | GraphicalChart @@ -939,17 +967,14 @@ prepareToReport inputFile Config{..} = do Just dir -> createDirectoryIfMissing True dir -- We assume the dataset is not big and therefore take liberties to process -- in a non-streaming fashion. - csvData <- parseCSVFromFile inputFile - case csvData of - Left e -> error $ show e - Right csvlines -> do - when (null csvlines) $ error $ "The input file [" - ++ show inputFile ++ "] is empty" - let allFields = head csvlines - fields = selectFields allFields - filterSanity "selectFields" allFields fields - let filt x = notElem (map toLower x) ["name", "iters"] - return (csvlines, filter filt fields) + csvlines <- parseCSVFromFile inputFile + when (null csvlines) $ error $ "The input file [" + ++ show inputFile ++ "] is empty" + let allFields = head csvlines + fields = selectFields allFields + filterSanity "selectFields" allFields fields + let filt x = notElem (map toLower x) ["name", "iters"] + return (csvlines, filter filt fields) -- Keep only those benchmarks that belong to the group. filterGroupBenchmarks :: [GroupMatrix] -> IO [GroupMatrix] From 97475eabf8a47154e1c7198eaee197f47a46eb23 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Thu, 27 Jan 2022 22:56:01 +0530 Subject: [PATCH 2/2] Update to latest stack resolver and add streamly to extra-deps --- stack.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stack.yaml b/stack.yaml index 3331aa4..8d8b5c9 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,7 @@ -resolver: lts-16.11 +resolver: lts-18.23 packages: - '.' +extra-deps: +- streamly-0.8.1.1 +- unicode-data-0.2.0 +- fusion-plugin-types-0.1.0