Skip to content

Commit

Permalink
Return the filepaths created in "createDirStucture"
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Feb 18, 2025
1 parent 9251483 commit 381b8ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
23 changes: 15 additions & 8 deletions bench-test-lib/src/BenchTestLib/DirIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module BenchTestLib.DirIO
-- Imports
--------------------------------------------------------------------------------

import Data.IORef (newIORef, modifyIORef', readIORef)
import Data.Maybe (fromJust)
import Data.Word (Word8)
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
Expand Down Expand Up @@ -120,14 +121,20 @@ streamDirChunked = either Dir.readEitherChunks (const Stream.nil)
-- Functions
--------------------------------------------------------------------------------

createDirStucture :: FilePath -> Int -> Int -> IO ()
createDirStucture _ depth _ | depth <= 0 = pure ()
createDirStucture parentDir depth width = do
for_ [1..width] $ \i -> do
let iStr = show i
subDir = [str|#{parentDir}/dir_#{iStr}|]
createDirectoryIfMissing True subDir
createDirStucture subDir (depth - 1) width
createDirStucture :: FilePath -> Int -> Int -> IO [FilePath]
createDirStucture root d w = do
ref <- newIORef [root]
createDirStucture_ ref root d w
readIORef ref
where
createDirStucture_ _ _ depth _ | depth <= 0 = pure ()
createDirStucture_ ref parentDir depth width = do
for_ [1..width] $ \i -> do
let iStr = show i
subDir = [str|#{parentDir}/dir_#{iStr}|]
createDirectoryIfMissing True subDir
modifyIORef' ref (subDir:)
createDirStucture_ ref subDir (depth - 1) width

#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
-- Fastest implementation, only works for posix as of now.
Expand Down
5 changes: 3 additions & 2 deletions benchmark/Streamly/Benchmark/FileSystem/DirIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Main (main) where
-- Imports
--------------------------------------------------------------------------------

import Control.Monad (void)
import GHC.IO.Encoding (setLocaleEncoding, utf8)
import Streamly.Benchmark.Common (o_1_space_prefix)

Expand All @@ -38,8 +39,8 @@ main = do

let smallTree = "benchmark-tmp/dir-structure-small"
bigTree = "benchmark-tmp/dir-structure-big"
createDirStucture smallTree 2 3
createDirStucture bigTree 5 5
void $ createDirStucture smallTree 2 3
void $ createDirStucture bigTree 5 5

defaultMain
[ bgroup (o_1_space_prefix moduleName)
Expand Down
16 changes: 4 additions & 12 deletions test/Streamly/Test/FileSystem/DirIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
-- Portability : GHC

{-# LANGUAGE CPP #-}
{-# LANGUAGE QuasiQuotes #-}

module Main (main) where

Expand All @@ -17,8 +16,6 @@ module Main (main) where

import Data.Word (Word8)
import GHC.IO.Encoding (setLocaleEncoding, utf8)
import Streamly.Unicode.String (str)
import System.Process (readCreateProcess, shell)
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
import Streamly.Data.Array (Array)
#endif
Expand Down Expand Up @@ -72,24 +69,19 @@ main = do

let smallTree = "benchmark-tmp/dir-structure-small"
bigTree = "benchmark-tmp/dir-structure-big"
createDirStucture smallTree 2 3
createDirStucture bigTree 5 5

findResBig <- readCreateProcess (shell [str|find #{bigTree}|]) ""
findResSmall <- readCreateProcess (shell [str|find #{smallTree}|]) ""
resSmall <- createDirStucture smallTree 2 3
resBig <- createDirStucture bigTree 5 5

strmBaseCacheSmall <-
Stream.fold Fold.toList
$ StreamK.toStream
$ StreamK.sortBy compare
$ StreamK.fromStream
$ Unicode.lines Fold.toList $ Stream.fromList findResSmall
$ StreamK.fromStream $ Stream.fromList resSmall
strmBaseCacheBig <-
Stream.fold Fold.toList
$ StreamK.toStream
$ StreamK.sortBy compare
$ StreamK.fromStream
$ Unicode.lines Fold.toList $ Stream.fromList findResBig
$ StreamK.fromStream $ Stream.fromList resBig
let strmBaseSmall = Stream.fromList strmBaseCacheSmall
let strmBaseBig = Stream.fromList strmBaseCacheBig

Expand Down

0 comments on commit 381b8ff

Please sign in to comment.