Skip to content

Commit f0a3f10

Browse files
authored
Merge pull request #594 from phadej/bench-escape
Add escape benchmark
2 parents 70f6023 + 0072772 commit f0a3f10

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

benchmarks/Escape.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{-# LANGUAGE PackageImports #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
3+
4+
module Main (main) where
5+
6+
import Prelude ()
7+
import Prelude.Compat
8+
9+
import Criterion.Main
10+
import qualified "aeson-benchmarks" Data.Aeson.Parser.UnescapeFFI as FFI
11+
import qualified "aeson-benchmarks" Data.Aeson.Parser.UnescapePure as Pure
12+
13+
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 "\\\""
20+
21+
main :: IO ()
22+
main = defaultMain
23+
[ bench "ffi" $ whnf FFI.unescapeText input
24+
, bench "pure" $ whnf Pure.unescapeText input
25+
]

benchmarks/aeson-benchmarks.cabal

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ library
8080
ghc-options: -O2 -Wall
8181
cpp-options: -DGENERICS
8282

83+
executable aeson-benchmark-escape
84+
main-is: Escape.hs
85+
hs-source-dirs: ../examples .
86+
ghc-options: -Wall -O2 -rtsopts
87+
build-depends:
88+
aeson-benchmarks,
89+
base,
90+
base-compat,
91+
bytestring,
92+
criterion >= 1.0,
93+
deepseq,
94+
ghc-prim,
95+
text
96+
8397
executable aeson-benchmark-compare
8498
main-is: Compare.hs
8599
hs-source-dirs: ../examples .

0 commit comments

Comments
 (0)