mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 19:47:10 +03:00
Fix benchmark names, cleanup imports, fix hlint
Refactor only.
This commit is contained in:
parent
fb1ee2e965
commit
f64dd78449
@ -64,4 +64,3 @@ benchmark/Streamly/Benchmark/Prelude/Serial/Transformation1.hs
|
||||
benchmark/Streamly/Benchmark/Prelude/WAsync.hs
|
||||
benchmark/Streamly/Benchmark/Prelude/ZipAsync.hs
|
||||
benchmark/Streamly/Benchmark/Prelude/ZipSerial.hs
|
||||
benchmark/Streamly/Benchmark/Unicode/Stream.hs
|
||||
|
@ -1,4 +1,4 @@
|
||||
-- |
|
||||
--
|
||||
-- Module : Streamly.Unicode.Stream
|
||||
-- Copyright : (c) 2019 Composewell Technologies
|
||||
-- License : BSD-3-Clause
|
||||
@ -21,16 +21,14 @@
|
||||
import Prelude hiding (last, length)
|
||||
import System.IO (Handle)
|
||||
|
||||
import qualified Streamly.Data.Fold as FL
|
||||
import qualified Streamly.Unicode.Stream as SS
|
||||
import qualified Streamly.FileSystem.Handle as FH
|
||||
import qualified Streamly.Internal.Data.Unfold as IUF
|
||||
import qualified Streamly.Internal.Unicode.Stream as IUS
|
||||
import qualified Streamly.Internal.FileSystem.Handle as IFH
|
||||
import qualified Streamly.Internal.Unicode.Array.Char as IUA
|
||||
import qualified Streamly.Internal.Data.Stream.IsStream as IP
|
||||
import qualified Streamly.Data.Array.Foreign as A
|
||||
import qualified Streamly.Prelude as S
|
||||
import qualified Streamly.Data.Array.Foreign as Array
|
||||
import qualified Streamly.Data.Fold as Fold
|
||||
import qualified Streamly.FileSystem.Handle as Handle
|
||||
import qualified Streamly.Internal.Data.Stream.IsStream as Stream
|
||||
import qualified Streamly.Internal.Data.Unfold as Unfold
|
||||
import qualified Streamly.Internal.FileSystem.Handle as Handle
|
||||
import qualified Streamly.Internal.Unicode.Array.Char as UnicodeArr
|
||||
import qualified Streamly.Internal.Unicode.Stream as Unicode
|
||||
|
||||
import Gauge hiding (env)
|
||||
import Streamly.Benchmark.Common
|
||||
@ -41,8 +39,8 @@ import Foreign.Storable (Storable)
|
||||
import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
|
||||
import qualified Streamly.Internal.Data.Fold.Type as Fold
|
||||
import qualified Streamly.Internal.Data.Tuple.Strict as Strict
|
||||
import qualified Streamly.Internal.Data.Array.Foreign.Type as AT
|
||||
import qualified Streamly.Internal.Data.Array.Foreign.Mut.Type as MA
|
||||
import qualified Streamly.Internal.Data.Array.Foreign.Type as Array
|
||||
import qualified Streamly.Internal.Data.Array.Foreign.Mut.Type as MArray
|
||||
|
||||
import Test.Inspection
|
||||
#endif
|
||||
@ -54,10 +52,10 @@ moduleName = "Unicode.Stream"
|
||||
{-# NOINLINE copyCodecUtf8ArraysLenient #-}
|
||||
copyCodecUtf8ArraysLenient :: Handle -> Handle -> IO ()
|
||||
copyCodecUtf8ArraysLenient inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeUtf8'
|
||||
$ IUS.decodeUtf8Arrays
|
||||
$ IFH.toChunks inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeUtf8'
|
||||
$ Unicode.decodeUtf8Arrays
|
||||
$ Handle.toChunks inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses 'copyCodecUtf8ArraysLenient
|
||||
@ -68,7 +66,7 @@ o_1_space_decode_encode_chunked :: BenchEnv -> [Benchmark]
|
||||
o_1_space_decode_encode_chunked env =
|
||||
[ bgroup "decode-encode/toChunks"
|
||||
[
|
||||
mkBenchSmall "decodeEncodeUtf8Lenient" env $ \inH outH ->
|
||||
mkBenchSmall "encodeUtf8' . decodeUtf8Arrays" env $ \inH outH ->
|
||||
copyCodecUtf8ArraysLenient inH outH
|
||||
]
|
||||
]
|
||||
@ -80,60 +78,60 @@ o_1_space_decode_encode_chunked env =
|
||||
{-# NOINLINE linesUnlinesCopy #-}
|
||||
linesUnlinesCopy :: Handle -> Handle -> IO ()
|
||||
linesUnlinesCopy inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeLatin1'
|
||||
$ IUS.unlines IUF.fromList
|
||||
$ S.splitOnSuffix (== '\n') FL.toList
|
||||
$ SS.decodeLatin1
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeLatin1'
|
||||
$ Unicode.unlines Unfold.fromList
|
||||
$ Stream.splitOnSuffix (== '\n') Fold.toList
|
||||
$ Unicode.decodeLatin1
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
{-# NOINLINE linesUnlinesArrayWord8Copy #-}
|
||||
linesUnlinesArrayWord8Copy :: Handle -> Handle -> IO ()
|
||||
linesUnlinesArrayWord8Copy inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ IP.interposeSuffix 10 A.read
|
||||
$ S.splitOnSuffix (== 10) A.write
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Stream.interposeSuffix 10 Array.read
|
||||
$ Stream.splitOnSuffix (== 10) Array.write
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
-- XXX splitSuffixOn requires -funfolding-use-threshold=150 for better fusion
|
||||
-- | Lines and unlines
|
||||
{-# NOINLINE linesUnlinesArrayCharCopy #-}
|
||||
linesUnlinesArrayCharCopy :: Handle -> Handle -> IO ()
|
||||
linesUnlinesArrayCharCopy inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeLatin1'
|
||||
$ IUA.unlines
|
||||
$ IUA.lines
|
||||
$ SS.decodeLatin1
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeLatin1'
|
||||
$ UnicodeArr.unlines
|
||||
$ UnicodeArr.lines
|
||||
$ Unicode.decodeLatin1
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClassesExcept 'linesUnlinesArrayCharCopy [''Storable]
|
||||
-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''Step
|
||||
#endif
|
||||
|
||||
-- XXX to write this we need to be able to map decodeUtf8 on the A.read fold.
|
||||
-- XXX to write this we need to be able to map decodeUtf8 on the Array.read fold.
|
||||
-- For that we have to write decodeUtf8 as a Pipe.
|
||||
{-
|
||||
{-# INLINE linesUnlinesArrayUtf8Copy #-}
|
||||
linesUnlinesArrayUtf8Copy :: Handle -> Handle -> IO ()
|
||||
linesUnlinesArrayUtf8Copy inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeLatin1'
|
||||
$ IP.intercalate (A.fromList [10]) (pipe SS.decodeUtf8P A.read)
|
||||
$ S.splitOnSuffix (== '\n') (IFL.map SS.encodeUtf8' A.write)
|
||||
$ SS.decodeLatin1
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeLatin1'
|
||||
$ Stream.intercalate (Array.fromList [10]) (pipe Unicode.decodeUtf8P Array.read)
|
||||
$ Stream.splitOnSuffix (== '\n') (IFold.map Unicode.encodeUtf8' Array.write)
|
||||
$ Unicode.decodeLatin1
|
||||
$ Stream.unfold Handle.read inh
|
||||
-}
|
||||
|
||||
-- | Word, unwords and copy
|
||||
{-# NOINLINE wordsUnwordsCopyWord8 #-}
|
||||
wordsUnwordsCopyWord8 :: Handle -> Handle -> IO ()
|
||||
wordsUnwordsCopyWord8 inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ IP.interposeSuffix 32 IUF.fromList
|
||||
$ S.wordsBy isSp FL.toList
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Stream.interposeSuffix 32 Unfold.fromList
|
||||
$ Stream.wordsBy isSp Fold.toList
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses 'wordsUnwordsCopyWord8
|
||||
@ -144,9 +142,9 @@ inspect $ hasNoTypeClasses 'wordsUnwordsCopyWord8
|
||||
{-# NOINLINE wordsUnwordsCopy #-}
|
||||
wordsUnwordsCopy :: Handle -> Handle -> IO ()
|
||||
wordsUnwordsCopy inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeLatin1'
|
||||
$ IUS.unwords IUF.fromList
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeLatin1'
|
||||
$ Unicode.unwords Unfold.fromList
|
||||
-- XXX This pipeline does not fuse with wordsBy but fuses with splitOn
|
||||
-- with -funfolding-use-threshold=300. With wordsBy it does not fuse
|
||||
-- even with high limits for inlining and spec-constr ghc options. With
|
||||
@ -154,10 +152,10 @@ wordsUnwordsCopy inh outh =
|
||||
-- is no evidence in the core that a join point involving Step
|
||||
-- constructors is not getting inlined. Not being able to fuse at all in
|
||||
-- this case could be an unknown issue, need more investigation.
|
||||
$ S.wordsBy isSpace FL.toList
|
||||
-- -- $ S.splitOn isSpace FL.toList
|
||||
$ SS.decodeLatin1
|
||||
$ S.unfold FH.read inh
|
||||
$ Stream.wordsBy isSpace Fold.toList
|
||||
-- -- $ Stream.splitOn isSpace Fold.toList
|
||||
$ Unicode.decodeLatin1
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
-- inspect $ hasNoTypeClasses 'wordsUnwordsCopy
|
||||
@ -167,28 +165,28 @@ wordsUnwordsCopy inh outh =
|
||||
{-# NOINLINE wordsUnwordsCharArrayCopy #-}
|
||||
wordsUnwordsCharArrayCopy :: Handle -> Handle -> IO ()
|
||||
wordsUnwordsCharArrayCopy inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeLatin1'
|
||||
$ IUA.unwords
|
||||
$ IUA.words
|
||||
$ SS.decodeLatin1
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeLatin1'
|
||||
$ UnicodeArr.unwords
|
||||
$ UnicodeArr.words
|
||||
$ Unicode.decodeLatin1
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
o_1_space_copy_read_group_ungroup :: BenchEnv -> [Benchmark]
|
||||
o_1_space_copy_read_group_ungroup env =
|
||||
[ bgroup "ungroup-group"
|
||||
[ mkBenchSmall "US.unlines . S.splitOnSuffix ([Word8])" env
|
||||
[ mkBenchSmall "unlines . splitOnSuffix ([Word8])" env
|
||||
$ \inh outh -> linesUnlinesCopy inh outh
|
||||
, mkBenchSmall "S.interposeSuffix . S.splitOnSuffix(Array Word8)" env
|
||||
, mkBenchSmall "interposeSuffix . splitOnSuffix (Array Word8)" env
|
||||
$ \inh outh -> linesUnlinesArrayWord8Copy inh outh
|
||||
, mkBenchSmall "UA.unlines . UA.lines (Array Char)" env
|
||||
, mkBenchSmall "UnicodeArr.unlines . UnicodeArr.lines (Array Char)" env
|
||||
$ \inh outh -> linesUnlinesArrayCharCopy inh outh
|
||||
|
||||
, mkBenchSmall "S.interposeSuffix . S.wordsBy ([Word8])" env
|
||||
, mkBenchSmall "interposeSuffix . wordsBy ([Word8])" env
|
||||
$ \inh outh -> wordsUnwordsCopyWord8 inh outh
|
||||
, mkBenchSmall "US.unwords . S.wordsBy ([Char])" env
|
||||
, mkBenchSmall "unwords . wordsBy ([Char])" env
|
||||
$ \inh outh -> wordsUnwordsCopy inh outh
|
||||
, mkBenchSmall "UA.unwords . UA.words (Array Char)" env
|
||||
, mkBenchSmall "UnicodeArr.unwords . UnicodeArr.words (Array Char)" env
|
||||
$ \inh outh -> wordsUnwordsCharArrayCopy inh outh
|
||||
]
|
||||
]
|
||||
@ -201,55 +199,55 @@ o_1_space_copy_read_group_ungroup env =
|
||||
{-# NOINLINE copyStreamLatin1' #-}
|
||||
copyStreamLatin1' :: Handle -> Handle -> IO ()
|
||||
copyStreamLatin1' inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeLatin1'
|
||||
$ SS.decodeLatin1
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeLatin1'
|
||||
$ Unicode.decodeLatin1
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses 'copyStreamLatin1'
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''Step
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''MA.ReadUState -- FH.read/A.read
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''Unfold.ConcatState -- Handle.read/UF.many
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''MArray.ReadUState -- Handle.read/Array.read
|
||||
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''Fold.Step
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''Strict.Tuple3' -- FH.write/chunksOf
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''Array.ArrayUnsafe -- Handle.write/writeNUnsafe
|
||||
inspect $ 'copyStreamLatin1' `hasNoType` ''Strict.Tuple3' -- Handle.write/chunksOf
|
||||
#endif
|
||||
|
||||
-- | Copy file (encodeLatin1)
|
||||
{-# NOINLINE copyStreamLatin1 #-}
|
||||
copyStreamLatin1 :: Handle -> Handle -> IO ()
|
||||
copyStreamLatin1 inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeLatin1
|
||||
$ SS.decodeLatin1
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeLatin1
|
||||
$ Unicode.decodeLatin1
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses 'copyStreamLatin1
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''Step
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''MA.ReadUState -- FH.read/A.read
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''Unfold.ConcatState -- Handle.read/UF.many
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''MArray.ReadUState -- Handle.read/Array.read
|
||||
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''Fold.ManyState
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''Fold.Step
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''Strict.Tuple3' -- FH.write/chunksOf
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''Array.ArrayUnsafe -- Handle.write/writeNUnsafe
|
||||
inspect $ 'copyStreamLatin1 `hasNoType` ''Strict.Tuple3' -- Handle.write/chunksOf
|
||||
#endif
|
||||
|
||||
-- | Copy file
|
||||
_copyStreamUtf8' :: Handle -> Handle -> IO ()
|
||||
_copyStreamUtf8' inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeUtf8'
|
||||
$ SS.decodeUtf8'
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeUtf8'
|
||||
$ Unicode.decodeUtf8'
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses '_copyStreamUtf8'
|
||||
-- inspect $ '_copyStreamUtf8 `hasNoType` ''Step
|
||||
-- inspect $ '_copyStreamUtf8 `hasNoType` ''AT.FlattenState
|
||||
-- inspect $ '_copyStreamUtf8 `hasNoType` ''Array.FlattenState
|
||||
-- inspect $ '_copyStreamUtf8 `hasNoType` ''D.ConcatMapUState
|
||||
#endif
|
||||
|
||||
@ -257,15 +255,15 @@ inspect $ hasNoTypeClasses '_copyStreamUtf8'
|
||||
{-# NOINLINE copyStreamUtf8 #-}
|
||||
copyStreamUtf8 :: Handle -> Handle -> IO ()
|
||||
copyStreamUtf8 inh outh =
|
||||
S.fold (FH.write outh)
|
||||
$ SS.encodeUtf8
|
||||
$ SS.decodeUtf8
|
||||
$ S.unfold FH.read inh
|
||||
Stream.fold (Handle.write outh)
|
||||
$ Unicode.encodeUtf8
|
||||
$ Unicode.decodeUtf8
|
||||
$ Stream.unfold Handle.read inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses 'copyStreamUtf8
|
||||
-- inspect $ 'copyStreamUtf8Lax `hasNoType` ''Step
|
||||
-- inspect $ 'copyStreamUtf8Lax `hasNoType` ''AT.FlattenState
|
||||
-- inspect $ 'copyStreamUtf8Lax `hasNoType` ''Array.FlattenState
|
||||
-- inspect $ 'copyStreamUtf8Lax `hasNoType` ''D.ConcatMapUState
|
||||
#endif
|
||||
|
||||
@ -274,15 +272,16 @@ o_1_space_decode_encode_read env =
|
||||
[ bgroup "decode-encode"
|
||||
[
|
||||
-- This needs an ascii file, as decode just errors out.
|
||||
mkBench "SS.encodeLatin1' . SS.decodeLatin1" env $ \inh outh ->
|
||||
mkBench "encodeLatin1' . decodeLatin1" env $ \inh outh ->
|
||||
copyStreamLatin1' inh outh
|
||||
, mkBench "SS.encodeLatin1 . SS.decodeLatin1" env $ \inh outh ->
|
||||
, mkBench "encodeLatin1 . decodeLatin1" env $ \inh outh ->
|
||||
copyStreamLatin1 inh outh
|
||||
#ifdef DEVBUILD
|
||||
, mkBench "copyUtf8" env $ \inh outh ->
|
||||
-- Requires valid unicode input
|
||||
, mkBench "encodeUtf8' . decodeUtf8'" env $ \inh outh ->
|
||||
_copyStreamUtf8' inh outh
|
||||
#endif
|
||||
, mkBenchSmall "SS.encodeUtf8 . SS.decodeUtf8Lax" env $ \inh outh ->
|
||||
, mkBenchSmall "encodeUtf8 . decodeUtf8" env $ \inh outh ->
|
||||
copyStreamUtf8 inh outh
|
||||
]
|
||||
]
|
||||
@ -296,7 +295,7 @@ main = do
|
||||
where
|
||||
|
||||
allBenchmarks env =
|
||||
[ bgroup (o_1_space_prefix moduleName) $ Prelude.concat $
|
||||
[ bgroup (o_1_space_prefix moduleName) $ Prelude.concat
|
||||
[ o_1_space_copy_read_group_ungroup env
|
||||
, o_1_space_decode_encode_chunked env
|
||||
, o_1_space_decode_encode_read env
|
||||
|
Loading…
Reference in New Issue
Block a user