Skip to content

Commit a01478e

Browse files
committed
benchmarks: option to specify string pattern in Escape.hs
1 parent 5ac929b commit a01478e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

benchmarks/Escape.hs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ import qualified "aeson-benchmarks" Data.Aeson.Parser.UnescapeFFI as FFI
1111
import qualified "aeson-benchmarks" Data.Aeson.Parser.UnescapePure as Pure
1212

1313
import qualified Data.ByteString.Char8 as BS
14-
15-
n :: Int
16-
n = 10000
17-
18-
input :: BS.ByteString
19-
input = BS.concat $ replicate n $ BS.pack "\\\""
14+
import System.Environment (getArgs, withArgs)
2015

2116
main :: IO ()
22-
main = defaultMain
17+
main = do
18+
args_ <- getArgs
19+
let (args, p, n) =
20+
case args_ of
21+
"--pattern" : p : args_ -> k p args_
22+
_ -> k "\\\"" args_
23+
k p args_ =
24+
case args_ of
25+
"--repeat" : n : args_ -> (args_, p, read n)
26+
args_ -> (args_, p, 10000)
27+
input = BS.concat $ replicate n $ BS.pack p
28+
withArgs args $ defaultMain
2329
[ bench "ffi" $ whnf FFI.unescapeText input
2430
, bench "pure" $ whnf Pure.unescapeText input
2531
]

0 commit comments

Comments
 (0)