Skip to content

Commit 280fd8a

Browse files
committed
Merge remote-tracking branch 'github/pr/181'
2 parents c55501e + d54b763 commit 280fd8a

File tree

4 files changed

+12
-605
lines changed

4 files changed

+12
-605
lines changed

.github/workflows/test.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
cabal update
5353
cabal build --enable-tests --enable-benchmarks
5454
cabal test
55+
cabal bench
5556
cabal haddock
5657
cabal check
5758
cabal sdist
@@ -82,6 +83,7 @@ jobs:
8283
. ~/.ghcup/env
8384
cabal update
8485
cabal test
86+
cabal bench
8587
8688
# We use github.com/haskell self-hosted runners for ARM testing.
8789
# If they become unavailable in future, put ['armv7', 'aarch64']
@@ -105,13 +107,13 @@ jobs:
105107
uses: docker://hasufell/arm32v7-ubuntu-haskell:focal
106108
name: Run build (arm32v7 linux)
107109
with:
108-
args: sh -c "cabal update && ghcup install ghc --isolate=/usr --force 9.2.2 && cabal test -w ghc-9.2.2"
110+
args: sh -c "cabal update && ghcup install ghc --isolate=/usr --force 9.2.2 && cabal test -w ghc-9.2.2 && cabal bench -w ghc-9.2.2"
109111

110112
- if: matrix.arch == 'arm64v8'
111113
uses: docker://hasufell/arm64v8-ubuntu-haskell:focal
112114
name: Run build (arm64v8 linux)
113115
with:
114-
args: sh -c "cabal update && ghcup install ghc --isolate=/usr --force 9.2.2 && cabal test -w ghc-9.2.2"
116+
args: sh -c "cabal update && ghcup install ghc --isolate=/usr --force 9.2.2 && cabal test -w ghc-9.2.2 && cabal bench -w ghc-9.2.2"
115117

116118
darwin_arm:
117119
runs-on: ${{ matrix.os }}
@@ -143,5 +145,6 @@ jobs:
143145
. .github/scripts/env.sh
144146
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_INSTALL_NO_STACK=1 BOOTSTRAP_HASKELL_GHC_VERSION=${{ matrix.ghc }} BOOTSTRAP_HASKELL_ADJUST_BASHRC=yes sh
145147
cabal test
148+
cabal bench
146149
env:
147150
HOMEBREW_CHANGE_ARCH_TO_ARM: 1

bench/BenchFilePath.hs

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ module Main where
66

77
import System.OsPath.Types
88
import System.OsPath.Encoding ( ucs2le )
9-
import System.Environment
109
import qualified System.OsString.Internal.Types as OST
1110
import qualified Data.ByteString.Short as SBS
1211

13-
import TastyBench
14-
import Data.List
15-
import Data.Maybe
16-
import GHC.IO.Encoding
12+
import Test.Tasty.Bench
1713

1814
import qualified System.FilePath.Posix as PF
1915
import qualified System.FilePath.Posix as WF
@@ -22,45 +18,9 @@ import qualified System.OsString.Windows as WSP
2218
import qualified System.OsPath.Posix as APF
2319
import qualified System.OsPath.Windows as AWF
2420

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-
5721
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)
6424
[("splitExtension (posix)" , nf PF.splitExtension posixPath)
6525
,("splitExtension (windows)" , nf WF.splitExtension windowsPath)
6626
,("takeExtension (posix)" , nf PF.takeExtension posixPath)
@@ -149,9 +109,8 @@ main = do
149109
,("splitSearchPath (posix)" , nf PF.splitSearchPath posixSearchPath)
150110
,("splitSearchPath (windows)" , nf WF.splitSearchPath windowsSearchPath)
151111
]
152-
)
153112

154-
, ("filepath (AFPP)",
113+
, bgroup "filepath (AFPP)" $ map (uncurry bench)
155114
[ ("splitExtension (posix)" , nf APF.splitExtension posixPathAFPP)
156115
, ("splitExtension (windows)" , nf AWF.splitExtension windowsPathAFPP)
157116
, ("takeExtension (posix)" , nf APF.takeExtension posixPathAFPP)
@@ -240,9 +199,8 @@ main = do
240199
, ("splitSearchPath (posix)" , nf APF.splitSearchPath posixSearchPathAFPP)
241200
, ("splitSearchPath (windows)" , nf AWF.splitSearchPath windowsSearchPathAFPP)
242201
]
243-
)
244202

245-
, ("encoding/decoding",
203+
, bgroup "encoding/decoding" $ map (uncurry bench)
246204
[ ("decodeUtf (posix)" , nf (APF.decodeUtf @Maybe) posixPathAFPP)
247205
, ("decodeUtf (windows)" , nf (AWF.decodeUtf @Maybe) windowsPathAFPP)
248206
, ("decodeWith (windows)" , nf (AWF.decodeWith ucs2le) windowsPathAFPP)
@@ -259,7 +217,6 @@ main = do
259217
, ("fromBytes (posix)" , nf (OSP.fromBytes @Maybe) (SBS.fromShort . OST.getPosixString $ posixPathAFPP))
260218
, ("fromBytes (windows)" , nf (WSP.fromBytes @Maybe) (SBS.fromShort . OST.getWindowsString $ windowsPathAFPP))
261219
]
262-
)
263220
]
264221

265222

@@ -286,26 +243,3 @@ posixSearchPathAFPP = [OSP.pstr|:foo:bar:bath:baz:baz:tz:fooooooooooooooo:laaaaa
286243

287244
windowsSearchPathAFPP :: WindowsString
288245
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

Comments
 (0)