Skip to content

Commit fb742b1

Browse files
committed
Use smaller directory trees to bench and test BFS traversals
1 parent efebb6b commit fb742b1

File tree

3 files changed

+82
-59
lines changed
  • bench-test-lib/src/BenchTestLib
  • benchmark/Streamly/Benchmark/FileSystem
  • test/Streamly/Test/FileSystem

3 files changed

+82
-59
lines changed

bench-test-lib/src/BenchTestLib/DirIO.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
-- Stability : experimental
77
-- Portability : GHC
88

9+
{-# LANGUAGE QuasiQuotes #-}
10+
911
module BenchTestLib.DirIO
1012
( createDirStucture
1113
, listDirUnfoldDfs
@@ -41,6 +43,7 @@ import Streamly.Data.Stream (Stream)
4143
import Streamly.Data.Unfold (Unfold)
4244
import Streamly.FileSystem.Path (Path)
4345
import System.Process (callCommand)
46+
import Streamly.Unicode.String (str)
4447

4548
import qualified Streamly.Data.Stream.Prelude as Stream
4649
import qualified Streamly.Data.Array as Array
@@ -110,10 +113,12 @@ streamDirChunked = either Dir.readEitherChunks (const Stream.nil)
110113
-- Functions
111114
--------------------------------------------------------------------------------
112115

113-
createDirStucture :: FilePath -> IO ()
114-
createDirStucture dirRoot = do
115-
let cmd =
116-
"bench-test-lib/create_dir_structure.sh " ++ dirRoot ++ " 5 5"
116+
createDirStucture :: FilePath -> Int -> Int -> IO ()
117+
createDirStucture dirRoot depth width = do
118+
let dStr = show depth
119+
wStr = show width
120+
cmd =
121+
[str|./bench-test-lib/create_dir_structure.sh #{dirRoot} #{dStr} #{wStr}|]
117122
callCommand ("mkdir -p " ++ dirRoot)
118123
callCommand cmd
119124

benchmark/Streamly/Benchmark/FileSystem/DirIO.hs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,48 @@ import BenchTestLib.DirIO
3232
moduleName :: String
3333
moduleName = "FileSystem.DirIO"
3434

35-
#define BENCH(x) \
35+
#define BENCH(x,fp) \
3636
bench " x " $ nfIO $ \
37-
Stream.fold Fold.drain $ x dirRoot
37+
Stream.fold Fold.drain $ x fp
3838

3939
-- | List the current directory recursively
4040
main :: IO ()
4141
main = do
4242
setLocaleEncoding utf8
4343

44-
let dirRoot = "benchmark-tmp/dir-structure"
45-
createDirStucture dirRoot
44+
let smallTree = "benchmark-tmp/dir-structure-small"
45+
bigTree = "benchmark-tmp/dir-structure-big"
46+
createDirStucture smallTree 2 3
47+
createDirStucture bigTree 5 5
4648

4749
defaultMain
4850
[ bgroup (o_1_space_prefix moduleName)
4951
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
5052
$ (bench "listDirByteChunked" $ nfIO $
51-
Stream.fold Fold.drain $ listDirByteChunked dirRoot) :
53+
Stream.fold Fold.drain $ listDirByteChunked bigTree) :
5254
#endif
53-
[ BENCH(listDirUnfoldDfs)
54-
-- NOTE: The BFS traversal fails with:
55-
-- openDirStream: resource exhausted (Too many open files)
56-
, BENCH(listDirUnfoldDfs)
57-
-- , BENCH(listDirUnfoldBfs)
58-
-- , BENCH(listDirUnfoldBfsRev)
59-
, BENCH(listDirConcatDfs)
60-
-- , BENCH(listDirConcatBfs)
61-
-- , BENCH(listDirConcatBfsRev)
62-
, BENCH(listDirAppend)
63-
, BENCH(listDirInterleave)
64-
, BENCH(listDirPar)
65-
, BENCH(listDirParInterleaved)
66-
, BENCH(listDirParOrdered)
67-
, BENCH(listDirChunkDfs)
68-
-- , BENCH(listDirChunkBfs)
69-
-- , BENCH(listDirChunkBfsRev)
70-
, BENCH(listDirChunkAppend)
71-
, BENCH(listDirChunkInterleave)
72-
, BENCH(listDirChunkPar)
73-
, BENCH(listDirChunkParInterleaved)
74-
, BENCH(listDirChunkParOrdered)
55+
-- NOTE: The BFS traversal fails with:
56+
-- openDirStream: resource exhausted (Too many open files)
57+
-- if a bigger directory tree is used
58+
[ BENCH(listDirUnfoldDfs,bigTree)
59+
, BENCH(listDirUnfoldDfs,bigTree)
60+
, BENCH(listDirUnfoldBfs,smallTree)
61+
, BENCH(listDirUnfoldBfsRev,smallTree)
62+
, BENCH(listDirConcatDfs,bigTree)
63+
, BENCH(listDirConcatBfs,smallTree)
64+
, BENCH(listDirConcatBfsRev,smallTree)
65+
, BENCH(listDirAppend,bigTree)
66+
, BENCH(listDirInterleave,bigTree)
67+
, BENCH(listDirPar,bigTree)
68+
, BENCH(listDirParInterleaved,bigTree)
69+
, BENCH(listDirParOrdered,bigTree)
70+
, BENCH(listDirChunkDfs,bigTree)
71+
, BENCH(listDirChunkBfs,smallTree)
72+
, BENCH(listDirChunkBfsRev,smallTree)
73+
, BENCH(listDirChunkAppend,bigTree)
74+
, BENCH(listDirChunkInterleave,bigTree)
75+
, BENCH(listDirChunkPar,bigTree)
76+
, BENCH(listDirChunkParInterleaved,bigTree)
77+
, BENCH(listDirChunkParOrdered,bigTree)
7578
]
7679
]

test/Streamly/Test/FileSystem/DirIO.hs

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,49 +61,64 @@ testCorrectnessByteChunked strmBase lister = do
6161
$ Unicode.decodeUtf8Chunks lister
6262
Stream.eqBy (==) strm strmBase `shouldReturn` True
6363

64-
#define IT(x) \
64+
#define IT(x,sb,dr) \
6565
it " x " $ \
66-
testCorrectness strmBase (x dirRoot)
66+
testCorrectness sb (x dr)
6767

6868
-- | List the current directory recursively
6969
main :: IO ()
7070
main = do
7171
setLocaleEncoding utf8
72-
let dirRoot = "benchmark-tmp/dir-structure"
73-
createDirStucture dirRoot
74-
findRes <- readCreateProcess ((shell [str|find #{dirRoot}|])) ""
75-
strmBaseCache <-
72+
73+
let smallTree = "benchmark-tmp/dir-structure-small"
74+
bigTree = "benchmark-tmp/dir-structure-big"
75+
createDirStucture smallTree 2 3
76+
createDirStucture bigTree 5 5
77+
78+
findResBig <- readCreateProcess (shell [str|find #{bigTree}|]) ""
79+
findResSmall <- readCreateProcess (shell [str|find #{smallTree}|]) ""
80+
81+
strmBaseCacheSmall <-
82+
Stream.fold Fold.toList
83+
$ StreamK.toStream
84+
$ StreamK.sortBy compare
85+
$ StreamK.fromStream
86+
$ Unicode.lines Fold.toList $ Stream.fromList findResSmall
87+
strmBaseCacheBig <-
7688
Stream.fold Fold.toList
7789
$ StreamK.toStream
7890
$ StreamK.sortBy compare
7991
$ StreamK.fromStream
80-
$ Unicode.lines Fold.toList $ Stream.fromList findRes
81-
let strmBase = Stream.fromList strmBaseCache
92+
$ Unicode.lines Fold.toList $ Stream.fromList findResBig
93+
let strmBaseSmall = Stream.fromList strmBaseCacheSmall
94+
let strmBaseBig = Stream.fromList strmBaseCacheBig
95+
8296
hspec $
8397
describe moduleName $ do
8498
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
8599
it "listDirByteChunked" $
86100
testCorrectnessByteChunked
87-
(Stream.drop 1 strmBase) (listDirByteChunked dirRoot)
101+
(Stream.drop 1 strmBaseBig) (listDirByteChunked bigTree)
88102
#endif
89103
-- NOTE: The BFS traversal fails with:
90104
-- openDirStream: resource exhausted (Too many open files)
91-
IT(listDirUnfoldDfs)
92-
-- IT(listDirUnfoldBfs)
93-
-- IT(listDirUnfoldBfsRev)
94-
IT(listDirConcatDfs)
95-
-- IT(listDirConcatBfs)
96-
-- IT(listDirConcatBfsRev)
97-
IT(listDirAppend)
98-
IT(listDirInterleave)
99-
IT(listDirPar)
100-
IT(listDirParInterleaved)
101-
IT(listDirParOrdered)
102-
IT(listDirChunkDfs)
103-
-- IT(listDirChunkBfs)
104-
-- IT(listDirChunkBfsRev)
105-
IT(listDirChunkAppend)
106-
IT(listDirChunkInterleave)
107-
IT(listDirChunkPar)
108-
IT(listDirChunkParInterleaved)
109-
IT(listDirChunkParOrdered)
105+
-- if a bigger directory tree is used
106+
IT(listDirUnfoldDfs,strmBaseBig,bigTree)
107+
IT(listDirUnfoldBfs,strmBaseSmall,smallTree)
108+
IT(listDirUnfoldBfsRev,strmBaseSmall,smallTree)
109+
IT(listDirConcatDfs,strmBaseBig,bigTree)
110+
IT(listDirConcatBfs,strmBaseSmall,smallTree)
111+
IT(listDirConcatBfsRev,strmBaseSmall,smallTree)
112+
IT(listDirAppend,strmBaseBig,bigTree)
113+
IT(listDirInterleave,strmBaseBig,bigTree)
114+
IT(listDirPar,strmBaseBig,bigTree)
115+
IT(listDirParInterleaved,strmBaseBig,bigTree)
116+
IT(listDirParOrdered,strmBaseBig,bigTree)
117+
IT(listDirChunkDfs,strmBaseBig,bigTree)
118+
IT(listDirChunkBfs,strmBaseSmall,smallTree)
119+
IT(listDirChunkBfsRev,strmBaseSmall,smallTree)
120+
IT(listDirChunkAppend,strmBaseBig,bigTree)
121+
IT(listDirChunkInterleave,strmBaseBig,bigTree)
122+
IT(listDirChunkPar,strmBaseBig,bigTree)
123+
IT(listDirChunkParInterleaved,strmBaseBig,bigTree)
124+
IT(listDirChunkParOrdered,strmBaseBig,bigTree)

0 commit comments

Comments
 (0)