on master help sign in
Merge pull request #594 from phadej/bench-escape

Add escape benchmark

commitf0a3f10cd209425af69e0c50d1f3f91a71572032 authorAdam Bergmark <adam@bergmark.nl> dateThu 5 Oct 2017, 12:11 (9 years ago) parent70f60230072772
2 files changed+39
benchmarks/Escape.hs+25 benchmarks/aeson-benchmarks.cabal+14
benchmarks/Escape.hsnew file+25
@@ -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+14
@@ -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+
8397executable aeson-benchmark-compare
8498 main-is: Compare.hs
8599 hs-source-dirs: ../examples .