on master help sign in
rename FileSystem.File module to FileSystem.Handle
commit606fe9de747d8456714066dd35f6273bf79cf14f authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 30 May 2019, 08:31 (7 years ago) parent677c94d
4 files changed+147−150
benchmark/FileIO.hs+31−31 benchmark/NanoBenchmarks.hs+2−2 src/Streamly/FileSystem/File.hs → src/Streamly/FileSystem/Handle.hs+13−16 streamly.cabal+101−101
benchmark/FileIO.hs+31−31
@@ -15,7 +15,7 @@ import System.Process.Typed (shell, runProcess_)
1515import Data.IORef
1616import Gauge
1717
18−import qualified Streamly.FileSystem.File as File
18+import qualified Streamly.FileSystem.Handle as FH
1919import qualified Streamly.Mem.Array as A
2020import qualified Streamly.Prelude as S
2121
@@ -91,7 +91,7 @@ main = do
9191 [ bgroup "readArray"
9292 [ mkBench "last" href $ do
9393 Handles inh _ <- readIORef href
94− let s = File.readArrays inh
94+ let s = FH.readArrays inh
9595 larr <- S.last s
9696 return $ case larr of
9797 Nothing -> Nothing
@@ -101,53 +101,53 @@ main = do
101101 -- and counting characters.
102102 , mkBench "length (bytecount)" href $ do
103103 Handles inh _ <- readIORef href
104− let s = File.readArrays inh
104+ let s = FH.readArrays inh
105105 S.sum (S.map A.length s)
106106 , mkBench "sum" href $ do
107107 let foldlArr' f z = runIdentity . S.foldl' f z . A.read
108108 Handles inh _ <- readIORef href
109− let s = File.readArrays inh
109+ let s = FH.readArrays inh
110110 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
111111 ]
112112 , bgroup "readStream"
113113 [ mkBench "last" href $ do
114114 Handles inh _ <- readIORef href
115− S.last $ File.read inh
115+ S.last $ FH.read inh
116116 , mkBench "length (bytecount)" href $ do
117117 Handles inh _ <- readIORef href
118− S.length $ File.read inh
118+ S.length $ FH.read inh
119119 , mkBench "sum" href $ do
120120 Handles inh _ <- readIORef href
121− S.sum $ File.read inh
121+ S.sum $ FH.read inh
122122 ]
123123 , bgroup "copyArray"
124124 [ mkBench "copy" href $ do
125125 Handles inh outh <- readIORef href
126− let s = File.readArrays inh
127− File.writeArrays outh s
126+ let s = FH.readArrays inh
127+ FH.writeArrays outh s
128128 ]
129129#ifdef DEVBUILD
130130 -- This takes a little longer therefore put under the dev conditional
131131 , bgroup "copyStream"
132132 [ mkBench "fromToHandle" href $ do
133133 Handles inh outh <- readIORef href
134− File.write outh (File.read inh)
134+ FH.write outh (FH.read inh)
135135 ]
136136 , bgroup "grouping"
137137 [ mkBench "chunksOf 1 (toArray)" href $ do
138138 Handles inh _ <- readIORef href
139139 S.length $ FL.chunksOf fileSize (A.toArrayN fileSize)
140− (File.read inh)
140+ (FH.read inh)
141141
142142 , mkBench "chunksOf 1" href $ do
143143 Handles inh _ <- readIORef href
144− S.length $ FL.chunksOf 1 FL.drain (File.read inh)
144+ S.length $ FL.chunksOf 1 FL.drain (FH.read inh)
145145 , mkBench "chunksOf 10" href $ do
146146 Handles inh _ <- readIORef href
147− S.length $ FL.chunksOf 10 FL.drain (File.read inh)
147+ S.length $ FL.chunksOf 10 FL.drain (FH.read inh)
148148 , mkBench "chunksOf 1000" href $ do
149149 Handles inh _ <- readIORef href
150− S.length $ FL.chunksOf 1000 FL.drain (File.read inh)
150+ S.length $ FL.chunksOf 1000 FL.drain (FH.read inh)
151151 ]
152152
153153 , let lf = fromIntegral (ord '\n')
@@ -158,66 +158,66 @@ main = do
158158 [ bgroup "predicate"
159159 [ mkBenchText "splitBy \\n (line count)" inText $ do
160160 (S.length $ FL.splitBy (== lf) FL.drain
161− $ File.read inText) >>= print
161+ $ FH.read inText) >>= print
162162 , mkBenchText "splitSuffixBy \\n (line count)" inText $ do
163163 (S.length $ FL.splitSuffixBy (== lf) FL.drain
164− $ File.read inText) >>= print
164+ $ FH.read inText) >>= print
165165 , mkBenchText "wordsBy isSpace (word count)" inText $ do
166166 (S.length $ FL.wordsBy isSp FL.drain
167− $ File.read inText) >>= print
167+ $ FH.read inText) >>= print
168168 ]
169169
170170 , bgroup "empty-pattern"
171171 [ mkBenchText "splitOn \"\"" inText $ do
172172 (S.length $ FL.splitOn (A.fromList []) FL.drain
173− $ File.read inText) >>= print
173+ $ FH.read inText) >>= print
174174 , mkBenchText "splitSuffixOn \"\"" inText $ do
175175 (S.length $ FL.splitSuffixOn (A.fromList []) FL.drain
176− $ File.read inText) >>= print
176+ $ FH.read inText) >>= print
177177 ]
178178 , bgroup "short-pattern"
179179 [ mkBenchText "splitOn \\n (line count)" inText $ do
180180 (S.length $ FL.splitOn lfarr FL.drain
181− $ File.read inText) >>= print
181+ $ FH.read inText) >>= print
182182 , mkBenchText "splitSuffixOn \\n (line count)" inText $ do
183183 (S.length $ FL.splitSuffixOn lfarr FL.drain
184− $ File.read inText) >>= print
184+ $ FH.read inText) >>= print
185185 , mkBenchText "splitOn a" inText $ do
186186 (S.length $ FL.splitOn (toarr "a") FL.drain
187− $ File.read inText) >>= print
187+ $ FH.read inText) >>= print
188188 , mkBenchText "splitOn \\r\\n" inText $ do
189189 (S.length $ FL.splitOn (toarr "\r\n") FL.drain
190− $ File.read inText) >>= print
190+ $ FH.read inText) >>= print
191191 , mkBenchText "splitSuffixOn \\r\\n)" inText $ do
192192 (S.length $ FL.splitSuffixOn (toarr "\r\n") FL.drain
193− $ File.read inText) >>= print
193+ $ FH.read inText) >>= print
194194 , mkBenchText "splitOn aa" inText $ do
195195 (S.length $ FL.splitOn (toarr "aa") FL.drain
196− $ File.read inText) >>= print
196+ $ FH.read inText) >>= print
197197 , mkBenchText "splitOn aaaa" inText $ do
198198 (S.length $ FL.splitOn (toarr "aaaa") FL.drain
199− $ File.read inText) >>= print
199+ $ FH.read inText) >>= print
200200 , mkBenchText "splitOn abcdefgh" inText $ do
201201 (S.length $ FL.splitOn (toarr "abcdefgh") FL.drain
202− $ File.read inText) >>= print
202+ $ FH.read inText) >>= print
203203 ]
204204 , bgroup "long-pattern"
205205 [ mkBenchText "splitOn abcdefghi" inText $ do
206206 (S.length $ FL.splitOn (toarr "abcdefghi") FL.drain
207− $ File.read inText) >>= print
207+ $ FH.read inText) >>= print
208208 , mkBenchText "splitOn catcatcatcatcat" inText $ do
209209 (S.length $ FL.splitOn (toarr "catcatcatcatcat") FL.drain
210− $ File.read inText) >>= print
210+ $ FH.read inText) >>= print
211211 , mkBenchText "splitOn abc...xyz" inText $ do
212212 (S.length $ FL.splitOn
213213 (toarr "abcdefghijklmnopqrstuvwxyz")
214214 FL.drain
215− $ File.read inText) >>= print
215+ $ FH.read inText) >>= print
216216 , mkBenchText "splitSuffixOn abc...xyz" inText $ do
217217 (S.length $ FL.splitSuffixOn
218218 (toarr "abcdefghijklmnopqrstuvwxyz")
219219 FL.drain
220− $ File.read inText) >>= print
220+ $ FH.read inText) >>= print
221221 ]
222222 ]
223223#endif
benchmark/NanoBenchmarks.hs+2−2
@@ -10,7 +10,7 @@ import Streamly (SerialT)
1010import Streamly.SVar (MonadAsync)
1111
1212import qualified Streamly.Mem.Array as A
13−import qualified Streamly.FileSystem.File as File
13+import qualified Streamly.FileSystem.Handle as FH
1414import qualified Streamly.Fold as FL
1515import qualified Streamly.Prelude as S
1616import qualified Streamly.Streams.StreamK as K
@@ -112,7 +112,7 @@ main = do
112112 defaultMain [mkBenchText "splitOn abc...xyz" inText $ do
113113 (S.length $ FL.splitOn (A.fromList $ map (fromIntegral . ord)
114114 "abcdefghijklmnopqrstuvwxyz") FL.drain
115− $ File.read inText) >>= print
115+ $ FH.read inText) >>= print
116116 ]
117117 where
118118
src/Streamly/FileSystem/File.hs → src/Streamly/FileSystem/Handle.hsrenamed+13−16
@@ -7,7 +7,7 @@
77#include "inline.hs"
88
99-- |
10−-- Module : Streamly.FileSystem.File
10+-- Module : Streamly.FileSystem.Handle
1111-- Copyright : (c) 2018 Harendra Kumar
1212--
1313-- License : BSD3
@@ -15,19 +15,20 @@
1515-- Stability : experimental
1616-- Portability : GHC
1717--
18−-- Read and write streams and arrays to and from files. File IO APIs are quite
19−-- similar to "Streamly.Mem.Array" read write APIs. In that regard, arrays can
20−-- be considered as in-memory files or files can be considered as on-disk
21−-- arrays. IO APIs are divided into two categories, sequential streaming IO
22−-- APIs and random access IO APIs. Control over the file reading and writing
23−-- behavior in terms of buffering, encoding, decoding is in the hands of the
24−-- programmer, the 'TextEncoding', 'NewLineMode', and 'Buffering' options of
25−-- the underlying handle provided by GHC are not needed and ignored.
18+-- Read and write streams and arrays to and from file handles. File handle IO
19+-- APIs are quite similar to "Streamly.Mem.Array" read write APIs. In that
20+-- regard, arrays can be considered as in-memory files or files can be
21+-- considered as on-disk arrays. IO APIs are divided into two categories,
22+-- sequential streaming IO APIs and random access IO APIs. Control over the
23+-- file reading and writing behavior in terms of buffering, encoding, decoding
24+-- is in the hands of the programmer, the 'TextEncoding', 'NewLineMode', and
25+-- 'Buffering' options of the underlying handle provided by GHC are not needed
26+-- and ignored.
2627--
27−-- > import qualified Streamly.FileSystem.File as File
28+-- > import qualified Streamly.FileSystem.Handle as FH
2829--
2930
30−module Streamly.FileSystem.File
31+module Streamly.FileSystem.Handle
3132 (
3233 -- * Streaming IO
3334 -- | Stream data to or from a file or device sequentially. When reading,
@@ -47,11 +48,7 @@ module Streamly.FileSystem.File
4748 -- Devices like terminals, pipes, sockets and fifos do not have random
4849 -- access capability.
4950
50− -- TODO file path based APIs
51− -- , readFile
52− -- , writeFile
53−
54− -- ** Read File to Stream
51+ -- ** Read Handle to Stream
5552 read
5653 -- , readUtf8
5754 -- , readLines
streamly.cabal+101−101
@@ -215,7 +215,7 @@ library
215215
216216 -- IO devices
217217 , Streamly.Mem.Array
218− , Streamly.FileSystem.File
218+ , Streamly.FileSystem.Handle
219219 , Streamly.Network.Socket
220220
221221 -- Time
@@ -538,40 +538,40 @@ benchmark linear-async
538538 if impl(ghc < 8.0)
539539 build-depends:
540540 transformers >= 0.4 && < 0.6
541−--
542−-- benchmark linear-rate
543−-- type: exitcode-stdio-1.0
544−-- hs-source-dirs: benchmark
545−-- main-is: LinearRate.hs
546−-- other-modules: LinearOps
547−-- default-language: Haskell2010
548−-- ghc-options: -O2 -Wall -fspec-constr-recursive=10 -with-rtsopts "-T"
549−--
550−-- if flag(has-llvm)
551−-- ghc-options: -fllvm
552−--
553−-- if flag(dev)
554−-- ghc-options: -Wmissed-specialisations
555−-- -Wall-missed-specialisations
556−-- -fno-ignore-asserts
557−-- if impl(ghc >= 8.0)
558−-- ghc-options: -Wcompat
559−-- -Wunrecognised-warning-flags
560−-- -Widentities
561−-- -Wincomplete-record-updates
562−-- -Wincomplete-uni-patterns
563−-- -Wredundant-constraints
564−-- -Wnoncanonical-monad-instances
565−-- -Wnoncanonical-monadfail-instances
566−-- build-depends:
567−-- streamly
568−-- , base >= 4.8 && < 5
569−-- , deepseq >= 1.4.3 && < 1.5
570−-- , random >= 1.0 && < 2.0
571−-- , gauge >= 0.2.4 && < 0.3
572−-- if impl(ghc < 8.0)
573−-- build-depends:
574−-- transformers >= 0.4 && < 0.6
541+
542+benchmark linear-rate
543+ type: exitcode-stdio-1.0
544+ hs-source-dirs: benchmark
545+ main-is: LinearRate.hs
546+ other-modules: LinearOps
547+ default-language: Haskell2010
548+ ghc-options: -O2 -Wall -fspec-constr-recursive=10 -with-rtsopts "-T"
549+
550+ if flag(has-llvm)
551+ ghc-options: -fllvm
552+
553+ if flag(dev)
554+ ghc-options: -Wmissed-specialisations
555+ -Wall-missed-specialisations
556+ -fno-ignore-asserts
557+ if impl(ghc >= 8.0)
558+ ghc-options: -Wcompat
559+ -Wunrecognised-warning-flags
560+ -Widentities
561+ -Wincomplete-record-updates
562+ -Wincomplete-uni-patterns
563+ -Wredundant-constraints
564+ -Wnoncanonical-monad-instances
565+ -Wnoncanonical-monadfail-instances
566+ build-depends:
567+ streamly
568+ , base >= 4.8 && < 5
569+ , deepseq >= 1.4.3 && < 1.5
570+ , random >= 1.0 && < 2.0
571+ , gauge >= 0.2.4 && < 0.3
572+ if impl(ghc < 8.0)
573+ build-depends:
574+ transformers >= 0.4 && < 0.6
575575
576576benchmark nested
577577 type: exitcode-stdio-1.0
@@ -608,72 +608,72 @@ benchmark nested
608608 build-depends:
609609 transformers >= 0.4 && < 0.6
610610
611−-- benchmark array
612−-- type: exitcode-stdio-1.0
613−-- hs-source-dirs: benchmark
614−-- main-is: Array.hs
615−-- other-modules: ArrayOps
616−-- default-language: Haskell2010
617−-- ghc-options: -O2 -Wall -with-rtsopts "-T" -fspec-constr-recursive=10
618−--
619−-- if flag(has-llvm)
620−-- ghc-options: -fllvm
621−--
622−-- if flag(dev)
623−-- cpp-options: -DDEVBUILD
624−-- ghc-options: -Wmissed-specialisations
625−-- -Wall-missed-specialisations
626−-- -fno-ignore-asserts
627−-- if impl(ghc >= 8.0)
628−-- ghc-options: -Wcompat
629−-- -Wunrecognised-warning-flags
630−-- -Widentities
631−-- -Wincomplete-record-updates
632−-- -Wincomplete-uni-patterns
633−-- -Wredundant-constraints
634−-- -Wnoncanonical-monad-instances
635−-- -Wnoncanonical-monadfail-instances
636−-- build-depends:
637−-- streamly
638−-- , base >= 4.8 && < 5
639−-- , deepseq >= 1.4.3 && < 1.5
640−-- , random >= 1.0 && < 2.0
641−-- , gauge >= 0.2.4 && < 0.3
642−-- if impl(ghc < 8.0)
643−-- build-depends:
644−-- transformers >= 0.4 && < 0.6
645−--
646−-- benchmark fileio
647−-- type: exitcode-stdio-1.0
648−-- hs-source-dirs: benchmark
649−-- main-is: FileIO.hs
650−-- default-language: Haskell2010
651−-- ghc-options: -O2 -Wall -fspec-constr-recursive=10 -with-rtsopts "-T"
652−--
653−-- if flag(has-llvm)
654−-- ghc-options: -fllvm
655−--
656−-- if flag(dev)
657−-- cpp-options: -DDEVBUILD
658−-- ghc-options: -Wmissed-specialisations
659−-- -Wall-missed-specialisations
660−-- -fno-ignore-asserts
661−-- if impl(ghc >= 8.0)
662−-- ghc-options: -Wcompat
663−-- -Wunrecognised-warning-flags
664−-- -Widentities
665−-- -Wincomplete-record-updates
666−-- -Wincomplete-uni-patterns
667−-- -Wredundant-constraints
668−-- -Wnoncanonical-monad-instances
669−-- -Wnoncanonical-monadfail-instances
670−-- build-depends:
671−-- streamly
672−-- , base >= 4.8 && < 5
673−-- , gauge >= 0.2.4 && < 0.3
674−-- , typed-process >= 0.2.3 && < 0.3
675−-- , deepseq >= 1.4.3 && < 1.5
676−--
611+benchmark array
612+ type: exitcode-stdio-1.0
613+ hs-source-dirs: benchmark
614+ main-is: Array.hs
615+ other-modules: ArrayOps
616+ default-language: Haskell2010
617+ ghc-options: -O2 -Wall -with-rtsopts "-T" -fspec-constr-recursive=10
618+
619+ if flag(has-llvm)
620+ ghc-options: -fllvm
621+
622+ if flag(dev)
623+ cpp-options: -DDEVBUILD
624+ ghc-options: -Wmissed-specialisations
625+ -Wall-missed-specialisations
626+ -fno-ignore-asserts
627+ if impl(ghc >= 8.0)
628+ ghc-options: -Wcompat
629+ -Wunrecognised-warning-flags
630+ -Widentities
631+ -Wincomplete-record-updates
632+ -Wincomplete-uni-patterns
633+ -Wredundant-constraints
634+ -Wnoncanonical-monad-instances
635+ -Wnoncanonical-monadfail-instances
636+ build-depends:
637+ streamly
638+ , base >= 4.8 && < 5
639+ , deepseq >= 1.4.3 && < 1.5
640+ , random >= 1.0 && < 2.0
641+ , gauge >= 0.2.4 && < 0.3
642+ if impl(ghc < 8.0)
643+ build-depends:
644+ transformers >= 0.4 && < 0.6
645+
646+benchmark fileio
647+ type: exitcode-stdio-1.0
648+ hs-source-dirs: benchmark
649+ main-is: FileIO.hs
650+ default-language: Haskell2010
651+ ghc-options: -O2 -Wall -fspec-constr-recursive=10 -with-rtsopts "-T"
652+
653+ if flag(has-llvm)
654+ ghc-options: -fllvm
655+
656+ if flag(dev)
657+ cpp-options: -DDEVBUILD
658+ ghc-options: -Wmissed-specialisations
659+ -Wall-missed-specialisations
660+ -fno-ignore-asserts
661+ if impl(ghc >= 8.0)
662+ ghc-options: -Wcompat
663+ -Wunrecognised-warning-flags
664+ -Widentities
665+ -Wincomplete-record-updates
666+ -Wincomplete-uni-patterns
667+ -Wredundant-constraints
668+ -Wnoncanonical-monad-instances
669+ -Wnoncanonical-monadfail-instances
670+ build-depends:
671+ streamly
672+ , base >= 4.8 && < 5
673+ , gauge >= 0.2.4 && < 0.3
674+ , typed-process >= 0.2.3 && < 0.3
675+ , deepseq >= 1.4.3 && < 1.5
676+
677677-------------------------------------------------------------------------------
678678-- Internal benchmarks for unexposed modules
679679-------------------------------------------------------------------------------