on master help sign in
Update benchmarks
fe0c366Bryan O'Sullivan
benchmarks/AesonEncode.hs+13−12
@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns, CPP, OverloadedStrings #-}
2
2
3import Control.Exception
3import Control.Exception
4import Control.Monad
4import Control.Monad
@@ -8,35 +8,36 @@ import Data.Time.Clock
8import System.Environment (getArgs)
8import System.Environment (getArgs)
9import System.IO
9import System.IO
10import qualified Data.ByteString as B
10import qualified Data.ByteString as B
11−import qualified Data.ByteString.Lazy as L
12−import qualified Data.ByteString.Lazy.Internal as L
13import Control.DeepSeq
11import Control.DeepSeq
14
12
13+#if !MIN_VERSION_bytestring(0,10,0)
14+import qualified Data.ByteString.Lazy.Internal as L
15+
15instance NFData L.ByteString where
16instance NFData L.ByteString where
16 rnf = go
17 rnf = go
17 where go (L.Chunk _ cs) = go cs
18 where go (L.Chunk _ cs) = go cs
18 go L.Empty = ()
19 go L.Empty = ()
19 {-# INLINE rnf #-}
20 {-# INLINE rnf #-}
21+#endif
20
22
23+main :: IO ()
21main = do
24main = do
22 (cnt:args) <- getArgs
25 (cnt:args) <- getArgs
23 let count = read cnt :: Int
26 let count = read cnt :: Int
24 forM_ args $ \arg -> bracket (openFile arg ReadMode) hClose $ \h -> do
27 forM_ args $ \arg -> bracket (openFile arg ReadMode) hClose $ \h -> do
25 putStrLn $ arg ++ ":"
28 putStrLn $ arg ++ ":"
26 let refill = B.hGet h 16384
29 let refill = B.hGet h 16384
27− result <- parseWith refill json =<< refill
30+ result0 <- parseWith refill json =<< refill
28− r <- case result of
31+ r0 <- case result0 of
29− Done _ r -> return r
32+ Done _ r -> return r
30− _ -> fail $ "failed to read " ++ show arg
33+ _ -> fail $ "failed to read " ++ show arg
31 start <- getCurrentTime
34 start <- getCurrentTime
32 let loop !n r
35 let loop !n r
33 | n >= count = return ()
36 | n >= count = return ()
34 | otherwise = {-# SCC "loop" #-} do
37 | otherwise = {-# SCC "loop" #-} do
35− case result of
36− Done _ r -> rnf (encode r) `seq` loop (n+1) r
38+ rnf (encode r) `seq` loop (n+1) r
37− _ -> error $ "failed to read " ++ show arg
38− loop 0 r
39+ loop 0 r0
39 delta <- flip diffUTCTime start `fmap` getCurrentTime
40 delta <- flip diffUTCTime start `fmap` getCurrentTime
40 let rate = fromIntegral count / realToFrac delta :: Double
41 let rate = fromIntegral count / realToFrac delta :: Double
41 putStrLn $ " " ++ show delta
42 putStrLn $ " " ++ show delta
42− putStrLn $ " " ++ show (round rate) ++ " per second"
43+ putStrLn $ " " ++ show (round rate :: Int) ++ " per second"
benchmarks/CompareWithJSON.hs+9−5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
2
3
3import Blaze.ByteString.Builder (toLazyByteString)
4import Blaze.ByteString.Builder (toLazyByteString)
@@ -6,9 +7,16 @@ import Control.DeepSeq (NFData(rnf))
6import Criterion.Main
7import Criterion.Main
7import qualified Data.Aeson as A
8import qualified Data.Aeson as A
8import qualified Data.ByteString.Lazy as BL
9import qualified Data.ByteString.Lazy as BL
9−import qualified Data.ByteString.Lazy.Internal as BL
10import qualified Text.JSON as J
10import qualified Text.JSON as J
11
11
12+#if !MIN_VERSION_bytestring(0,10,0)
13+import qualified Data.ByteString.Lazy.Internal as BL
14+
15+instance NFData BL.ByteString where
16+ rnf (BL.Chunk _ bs) = rnf bs
17+ rnf BL.Empty = ()
18+#endif
19+
12instance (NFData v) => NFData (J.JSObject v) where
20instance (NFData v) => NFData (J.JSObject v) where
13 rnf o = rnf (J.fromJSObject o)
21 rnf o = rnf (J.fromJSObject o)
14
22
@@ -20,10 +28,6 @@ instance NFData J.JSValue where
20 rnf (J.JSArray lst) = rnf lst
28 rnf (J.JSArray lst) = rnf lst
21 rnf (J.JSObject o) = rnf o
29 rnf (J.JSObject o) = rnf o
22
30
23−instance NFData BL.ByteString where
24− rnf (BL.Chunk _ bs) = rnf bs
25− rnf BL.Empty = ()
26−
27decodeJ :: String -> J.JSValue
31decodeJ :: String -> J.JSValue
28decodeJ s =
32decodeJ s =
29 case J.decodeStrict s of
33 case J.decodeStrict s of