@@ -6,14 +6,10 @@ module Main where
6
6
7
7
import System.OsPath.Types
8
8
import System.OsPath.Encoding ( ucs2le )
9
- import System.Environment
10
9
import qualified System.OsString.Internal.Types as OST
11
10
import qualified Data.ByteString.Short as SBS
12
11
13
- import TastyBench
14
- import Data.List
15
- import Data.Maybe
16
- import GHC.IO.Encoding
12
+ import Test.Tasty.Bench
17
13
18
14
import qualified System.FilePath.Posix as PF
19
15
import qualified System.FilePath.Posix as WF
@@ -22,45 +18,9 @@ import qualified System.OsString.Windows as WSP
22
18
import qualified System.OsPath.Posix as APF
23
19
import qualified System.OsPath.Windows as AWF
24
20
25
-
26
- data Config = Config {
27
- format :: Format
28
- , stdev :: Double
29
- , timeout :: Integer
30
- }
31
-
32
- data Format = Print
33
- | CSV
34
- deriving (Read , Show )
35
-
36
- defaultConfig :: Config
37
- defaultConfig = Config defaultFormat defaultStdev defaultTimeout
38
-
39
- defaultFormat :: Format
40
- defaultFormat = Print
41
-
42
- defaultStdev :: Double
43
- defaultStdev = 0.02
44
-
45
- defaultTimeout :: Integer
46
- defaultTimeout = 800000
47
-
48
- parseConfig :: [String ] -> Config
49
- parseConfig [] = defaultConfig
50
- parseConfig xs =
51
- let format' = maybe defaultFormat (read . fromJust . stripPrefix " --format=" ) $ find (" --format=" `isPrefixOf` ) xs
52
- stdev' = maybe defaultStdev (read . fromJust . stripPrefix " --stdev=" ) $ find (" --stdev=" `isPrefixOf` ) xs
53
- timeout' = maybe defaultTimeout (read . fromJust . stripPrefix " --timeout=" ) $ find (" --timeout=" `isPrefixOf` ) xs
54
- in Config format' stdev' timeout'
55
-
56
-
57
21
main :: IO ()
58
- main = do
59
- setLocaleEncoding utf8
60
- args <- getArgs
61
- let config = parseConfig args
62
- benchGroup config
63
- [ (" filepath (string)" ,
22
+ main = defaultMain
23
+ [ bgroup " filepath (string)" $ map (uncurry bench)
64
24
[(" splitExtension (posix)" , nf PF. splitExtension posixPath)
65
25
,(" splitExtension (windows)" , nf WF. splitExtension windowsPath)
66
26
,(" takeExtension (posix)" , nf PF. takeExtension posixPath)
@@ -149,9 +109,8 @@ main = do
149
109
,(" splitSearchPath (posix)" , nf PF. splitSearchPath posixSearchPath)
150
110
,(" splitSearchPath (windows)" , nf WF. splitSearchPath windowsSearchPath)
151
111
]
152
- )
153
112
154
- , ( " filepath (AFPP)" ,
113
+ , bgroup " filepath (AFPP)" $ map ( uncurry bench)
155
114
[ (" splitExtension (posix)" , nf APF. splitExtension posixPathAFPP)
156
115
, (" splitExtension (windows)" , nf AWF. splitExtension windowsPathAFPP)
157
116
, (" takeExtension (posix)" , nf APF. takeExtension posixPathAFPP)
@@ -240,9 +199,8 @@ main = do
240
199
, (" splitSearchPath (posix)" , nf APF. splitSearchPath posixSearchPathAFPP)
241
200
, (" splitSearchPath (windows)" , nf AWF. splitSearchPath windowsSearchPathAFPP)
242
201
]
243
- )
244
202
245
- , ( " encoding/decoding" ,
203
+ , bgroup " encoding/decoding" $ map ( uncurry bench)
246
204
[ (" decodeUtf (posix)" , nf (APF. decodeUtf @ Maybe ) posixPathAFPP)
247
205
, (" decodeUtf (windows)" , nf (AWF. decodeUtf @ Maybe ) windowsPathAFPP)
248
206
, (" decodeWith (windows)" , nf (AWF. decodeWith ucs2le) windowsPathAFPP)
@@ -259,7 +217,6 @@ main = do
259
217
, (" fromBytes (posix)" , nf (OSP. fromBytes @ Maybe ) (SBS. fromShort . OST. getPosixString $ posixPathAFPP))
260
218
, (" fromBytes (windows)" , nf (WSP. fromBytes @ Maybe ) (SBS. fromShort . OST. getWindowsString $ windowsPathAFPP))
261
219
]
262
- )
263
220
]
264
221
265
222
@@ -286,26 +243,3 @@ posixSearchPathAFPP = [OSP.pstr|:foo:bar:bath:baz:baz:tz:fooooooooooooooo:laaaaa
286
243
287
244
windowsSearchPathAFPP :: WindowsString
288
245
windowsSearchPathAFPP = [WSP. pstr |foo;bar;bath;baz;baz;tz;fooooooooooooooo;laaaaaaaaaaaaaaa;baaaaaaaaaaaaar;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk;kkkkkkkkkkkkkkkkkk;h;h;h;a;s;r;a;h;gt;r;r;r;s;s.txt|]
289
-
290
-
291
- benchGroup :: Config -> [(String , [(String , Benchmarkable )])] -> IO ()
292
- benchGroup _ [] = pure ()
293
- benchGroup format ((name, benchs): xs) = do
294
- putStrLn name
295
- bench format benchs
296
- benchGroup format xs
297
-
298
- bench :: Config -> [(String , Benchmarkable )] -> IO ()
299
- bench _ [] = pure ()
300
- bench config@ Config {.. } (x: xs) = do
301
- let (name, benchmarkable) = x
302
- case format of
303
- CSV -> putStr (name ++ " ," )
304
- Print -> putStr (" " ++ name ++ " : " )
305
- est <- measureUntil CpuTime False (Timeout timeout " " ) (RelStDev stdev) benchmarkable
306
- case format of
307
- CSV -> putStr $ csvEstimate est
308
- Print -> putStr $ " \n " ++ prettyEstimate est
309
- putStr " \n "
310
- bench config xs
311
-
0 commit comments