Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace functionality of split with streamly #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bench-show.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ library
, directory >= 1.2 && < 1.4
, transformers >= 0.4 && < 0.7
, ansi-wl-pprint >= 0.6 && < 0.7
, split >= 0.2 && < 0.3
, streamly >= 0.8 && < 0.9
, statistics >= 0.15 && < 0.17
, vector >= 0.10 && < 0.13

Expand All @@ -139,7 +139,6 @@ executable bench-show
, directory >= 1.2 && < 1.4
, transformers >= 0.4 && < 0.7
, ansi-wl-pprint >= 0.6 && < 0.7
, split >= 0.2 && < 0.3
, statistics >= 0.15 && < 0.17
, vector >= 0.10 && < 0.13
, semigroups >= 0.18 && < 0.21
Expand All @@ -160,7 +159,7 @@ test-suite test
build-depends:
bench-show
, base >= 4.8 && < 4.17
, split >= 0.2 && < 0.3
, streamly >= 0.8 && < 0.9
, text >= 1.1.1 && < 2.1
-- , typed-process >= 0.1.0.0 && < 0.3

Expand All @@ -177,4 +176,4 @@ test-suite doc
build-depends:
bench-show
, base >= 4.8 && < 4.17
, split >= 0.2 && < 0.3
, streamly >= 0.8 && < 0.9
11 changes: 9 additions & 2 deletions lib/BenchShow/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import Control.Monad (when, unless)
import Data.Char (toLower)
import Data.Foldable (foldl')
import Data.Function ((&), on)
import Data.Functor.Identity (runIdentity)
import Data.List
(transpose, groupBy, (\\), find, sortBy, elemIndex, intersect,
intersectBy)
import Data.List.Split (linesBy)
import Data.Maybe (fromMaybe, mapMaybe)
import Data.Ord (comparing)
import Debug.Trace (trace)
Expand All @@ -60,6 +60,9 @@ import System.FilePath ((</>))
import Text.CSV (CSV, parseCSVFromFile)
import Text.Read (readMaybe)

import qualified Streamly.Prelude as Stream
import qualified Streamly.Data.Fold as Fold

import BenchShow.Analysis

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -854,7 +857,11 @@ filterFields fieldNames BenchmarkIterMatrix{..} =
splitRuns :: NumberedLines -> ([String], [NumberedLines])
splitRuns csvlines =
let header = snd $ head csvlines
ls = linesBy (\x -> snd x == header) (tail csvlines)
ls =
runIdentity
$ Stream.toList
$ Stream.splitOnSuffix (\x -> snd x == header) Fold.toList
$ Stream.fromList (tail csvlines)
in (header, ls)

readWithError :: Read a => Int -> String -> (String, String) -> a
Expand Down
5 changes: 4 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
resolver: lts-16.11
resolver: lts-18.23
packages:
- '.'
extra-deps:
- streamly-0.8.1.1
- unicode-data-0.2.0
12 changes: 10 additions & 2 deletions test/Doc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ module Main where

import Data.Ord (comparing)
import Data.List (sortBy)
import Data.List.Split (splitOn)
import Data.Functor.Identity (runIdentity)

import qualified Streamly.Prelude as Stream
import qualified Streamly.Data.Fold as Fold

import BenchShow

splitOn :: Eq a => a -> [a] -> [[a]]
splitOn d =
runIdentity
. Stream.toList . Stream.splitOn (== d) Fold.toList . Stream.fromList

main :: IO ()
main = do
let classifier name =
case splitOn "/" name of
case splitOn '/' name of
grp : rest -> Just (grp, concat rest)
_ -> Nothing

Expand Down
15 changes: 12 additions & 3 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ module Main where

import Data.Function (on)
import Data.List
import Data.List.Split (splitOn)
import Data.Functor.Identity (runIdentity)
-- import Data.Maybe (catMaybes)
-- import System.Process.Typed (readProcess_)

import qualified Streamly.Prelude as Stream
import qualified Streamly.Data.Fold as Fold

import BenchShow

-- import qualified Data.Text.Lazy as T
Expand All @@ -26,6 +30,11 @@ packages =
, "drinkery"
]

splitOn :: Eq a => a -> [a] -> [[a]]
splitOn d =
runIdentity
. Stream.toList . Stream.splitOn (== d) Fold.toList . Stream.fromList

-------------------------------------------------------------------------------
main :: IO ()
main = do
Expand Down Expand Up @@ -70,15 +79,15 @@ main = do
, "transformation/scan"
]
bsort bs =
let i = intersect (map (last . splitOn "/") prefixes) bs
let i = intersect (map (last . splitOn '/') prefixes) bs
in i ++ (bs \\ i)
cfg = defaultConfig
{ mkTitle = Just (\_ -> chartTitle)
, outputDir = Just "charts"
, classifyBenchmark = \bm ->
case any (`isPrefixOf` bm) prefixes of
True ->
let xs = reverse (splitOn "/" bm)
let xs = reverse (splitOn '/' bm)
in Just (suffixVersion (xs !! 0), xs !! 1)
False -> Nothing
, selectBenchmarks = \g -> bsort $
Expand Down