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 #-}
36import Control.DeepSeq (NFData(rnf))
37import Data.Char (ord, chr)
38import Data.Word (Word8)
39import System.IO (openFile, IOMode(..), Handle, hClose)
42import Gauge hiding (env)
45scratchDir = "benchmark-tmp/"
48outfile = scratchDir ++ "out.txt"
51inFileSmall = scratchDir ++ "in-10MB.txt"
54inFileBig = scratchDir ++ "in-100MB.txt"
56data RefHandles = RefHandles
62data Handles = Handles !Handle !Handle
64instance NFData Handles where
67data BenchEnv = BenchEnv
68 { href :: IORef RefHandles
72 , smallInFile :: String
76withScaling :: BenchEnv -> String -> String
78 let factor = round (fromIntegral (bigSize env)
79 / (fromIntegral (smallSize env) :: Double)) :: Int
82 else str ++ " (1/" ++ show factor ++ ")"
86 => (RefHandles -> Handles)
89 -> (Handle -> Handle -> IO b)
91mkBenchCommon mkHandles name env action =
92 bench name $ perRunEnv (do
93 r <- readIORef $ href env
101 smallInHandle <- openFile (smallInFile env) ReadMode
102 bigInHandle <- openFile (bigInFile env) ReadMode
103 outHandle <- openFile outfile WriteMode
105 let refHandles = RefHandles
106 { smallInH = smallInHandle
107 , bigInH = bigInHandle
108 , outputH = outHandle
112 writeIORef (href env) $ refHandles
113 return $ mkHandles refHandles
115 (\(Handles h1 h2) -> action h1 h2)
118 NFData b => String -> BenchEnv -> (Handle -> Handle -> IO b) -> Benchmark
119mkBench name env action = mkBenchCommon useBigH name env action
123 useBigH (RefHandles {bigInH = inh, outputH = outh}) = Handles inh outh
126 NFData b => String -> BenchEnv -> (Handle -> Handle -> IO b) -> Benchmark
127mkBenchSmall name env action =
128 mkBenchCommon useSmallH (withScaling env name) env action
132 useSmallH (RefHandles {smallInH = inh, outputH = outh}) = Handles inh outh
134foreign import ccall unsafe "u_iswspace"
135 iswspace :: Int -> Int
137-- Code copied from base/Data.Char to INLINE it
138{-# INLINE isSpace #-}
139isSpace :: Char -> Bool
140-- isSpace includes non-breaking space
141-- The magic 0x377 isn't really that magical. As of 2014, all the codepoints
142-- at or below 0x377 have been assigned, so we shouldn't have to worry about
143-- any new spaces appearing below there. It would probably be best to
144-- use branchless ||, but currently the eqLit transformation will undo that,
145-- so we'll do it like this until there's a way around that.
147 | uc <= 0x377 = uc == 32 || uc - 0x9 <= 4 || uc == 0xa0
148 | otherwise = iswspace (ord c) /= 0
150 uc = fromIntegral (ord c) :: Word
154isSp = isSpace . chr . fromIntegral
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