2-- Module : Streamly.Benchmark.FileSystem.Handle
3-- Copyright : (c) 2019 Composewell Technologies
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
11{-# LANGUAGE ScopedTypeVariables #-}
13#ifdef __HADDOCK_VERSION__
18{-# LANGUAGE TemplateHaskell #-}
19{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
22#if __GLASGOW_HASKELL__ >= 800
23import System.Directory (getFileSize)
25import System.Environment (lookupEnv)
26import System.IO (openFile, IOMode(..))
27import System.Process.Typed (shell, runProcess_)
28import Prelude hiding (last, length)
30import qualified Handle.ReadWrite as RW
31import qualified Handle.Read as RO
34import Gauge hiding (env)
35import Streamly.Benchmark.Common
38-------------------------------------------------------------------------------
40-------------------------------------------------------------------------------
43moduleName = "FileSystem.Handle"
45-------------------------------------------------------------------------------
47-------------------------------------------------------------------------------
50smallFileSize = 10 * 1024 * 1024
53bigFileSize = 100 * 1024 * 1024
58blockCount :: Int -> Int
59blockCount size = (size + blockSize - 1) `div` blockSize
61-------------------------------------------------------------------------------
63-------------------------------------------------------------------------------
67 (_, cfg, benches) <- parseCLIOpts defaultStreamSize
68 r <- lookupEnv "Benchmark.FileSystem.Handle.InputFile"
71 Just inFileName -> return (inFileName, inFileName)
73 -- XXX will this work on windows/msys?
75 "mkdir -p " ++ scratchDir
76 ++ "; test -e " ++ infile
77 ++ " || { echo \"creating input file " ++ infile
78 ++ "\" && dd if=/dev/random of=" ++ infile
79 ++ " bs=" ++ show blockSize
80 ++ " count=" ++ show (blockCount size)
82 runProcess_ (shell (cmd inFileSmall smallFileSize))
83 runProcess_ (shell (cmd inFileBig bigFileSize))
84 return (inFileSmall, inFileBig)
86 smallHandle <- openFile small ReadMode
87 bigHandle <- openFile big ReadMode
88 outHandle <- openFile outfile WriteMode
89 devNull <- openFile "/dev/null" WriteMode
91#if __GLASGOW_HASKELL__ >= 800
92 ssize <- fromIntegral <$> getFileSize small
93 bsize <- fromIntegral <$> getFileSize big
95 let ssize = smallFileSize
96 let bsize = bigFileSize
99 ref <- newIORef $ RefHandles
100 { smallInH = smallHandle
102 , outputH = outHandle
112 runMode (mode cfg) cfg benches (allBenchmarks env)
117 [ bgroup (o_1_space_prefix moduleName) $ Prelude.concat
118 [ RO.allBenchmarks env
119 , RW.allBenchmarks env
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list