|
| 1 | + |
| 2 | +-- | |
| 3 | +-- Module : Stream.SplitChunks |
| 4 | +-- Copyright : (c) 2019 Composewell Technologies |
| 5 | +-- License : BSD-3-Clause |
| 6 | + |
| 7 | +-- Stability : experimental |
| 8 | +-- Portability : GHC |
| 9 | + |
| 10 | +{-# LANGUAGE CPP #-} |
| 11 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 12 | + |
| 13 | +#ifdef __HADDOCK_VERSION__ |
| 14 | +#undef INSPECTION |
| 15 | +#endif |
| 16 | + |
| 17 | +#ifdef INSPECTION |
| 18 | +{-# LANGUAGE TemplateHaskell #-} |
| 19 | +{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-} |
| 20 | +#endif |
| 21 | + |
| 22 | +module Stream.SplitChunks (benchmarks) where |
| 23 | + |
| 24 | +import System.IO (Handle) |
| 25 | + |
| 26 | +import qualified Streamly.Internal.Data.Array as Array |
| 27 | +import qualified Streamly.Internal.Data.Fold as Fold |
| 28 | +import qualified Streamly.Internal.Data.Stream as Stream |
| 29 | +import qualified Streamly.Internal.FileSystem.Handle as Handle |
| 30 | +import qualified Streamly.Internal.Unicode.Stream as Unicode |
| 31 | + |
| 32 | +import Test.Tasty.Bench hiding (env) |
| 33 | +import Prelude hiding (last, length) |
| 34 | +import Streamly.Benchmark.Common |
| 35 | +import Streamly.Benchmark.Common.Handle |
| 36 | + |
| 37 | +#ifdef INSPECTION |
| 38 | +import Streamly.Internal.Data.Stream (Step(..)) |
| 39 | + |
| 40 | +import qualified Streamly.Internal.Data.MutArray as MutArray |
| 41 | +import qualified Streamly.Internal.Data.Unfold as Unfold |
| 42 | + |
| 43 | +import Test.Inspection |
| 44 | +#endif |
| 45 | + |
| 46 | +------------------------------------------------------------------------------- |
| 47 | +-- reduce with splitting transformations |
| 48 | +------------------------------------------------------------------------------- |
| 49 | + |
| 50 | +-- | Split on a character sequence. |
| 51 | +splitOnSeqUtf8 :: String -> Handle -> IO Int |
| 52 | +splitOnSeqUtf8 str inh = |
| 53 | + (Stream.fold Fold.length |
| 54 | + $ Stream.splitSepBySeq_ (Array.fromList str) Fold.drain |
| 55 | + $ Unicode.decodeUtf8Chunks |
| 56 | + $ Handle.readChunks inh) -- >>= print |
| 57 | + |
| 58 | +o_1_space_reduce_toChunks_split :: BenchEnv -> [Benchmark] |
| 59 | +o_1_space_reduce_toChunks_split env = |
| 60 | + [ bgroup "FileSplitSeqUtf8" |
| 61 | + [ mkBenchSmall "splitOnSeqUtf8 word abcdefgh" |
| 62 | + env $ \inh _ -> splitOnSeqUtf8 "abcdefgh" inh |
| 63 | + , mkBenchSmall "splitOnSeqUtf8 KR abcdefghijklmnopqrstuvwxyz" |
| 64 | + env $ \inh _ -> splitOnSeqUtf8 "abcdefghijklmnopqrstuvwxyz" inh |
| 65 | + ] |
| 66 | + ] |
| 67 | + |
| 68 | +benchmarks :: String -> BenchEnv -> [Benchmark] |
| 69 | +benchmarks moduleName env = |
| 70 | + [ bgroup (o_1_space_prefix moduleName) $ |
| 71 | + o_1_space_reduce_toChunks_split env |
| 72 | + ] |
0 commit comments