Skip to content
Browse files

Update benchmarks

  • Loading branch information...
1 parent fb81fbf commit aaed0563e4f6028ef79bcdb0447ff6a8cb7cafd2 @bos committed Jan 29, 2013
Showing with 22 additions and 17 deletions.
  1. +13 −12 benchmarks/AesonEncode.hs
  2. +9 −5 benchmarks/CompareWithJSON.hs
View
25 benchmarks/AesonEncode.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE BangPatterns, OverloadedStrings #-}
+{-# LANGUAGE BangPatterns, CPP, OverloadedStrings #-}
import Control.Exception
import Control.Monad
@@ -8,35 +8,36 @@ import Data.Time.Clock
import System.Environment (getArgs)
import System.IO
import qualified Data.ByteString as B
-import qualified Data.ByteString.Lazy as L
-import qualified Data.ByteString.Lazy.Internal as L
import Control.DeepSeq
+#if !MIN_VERSION_bytestring(0,10,0)
+import qualified Data.ByteString.Lazy.Internal as L
+
instance NFData L.ByteString where
rnf = go
where go (L.Chunk _ cs) = go cs
go L.Empty = ()
{-# INLINE rnf #-}
+#endif
+main :: IO ()
main = do
(cnt:args) <- getArgs
let count = read cnt :: Int
forM_ args $ \arg -> bracket (openFile arg ReadMode) hClose $ \h -> do
putStrLn $ arg ++ ":"
let refill = B.hGet h 16384
- result <- parseWith refill json =<< refill
- r <- case result of
- Done _ r -> return r
- _ -> fail $ "failed to read " ++ show arg
+ result0 <- parseWith refill json =<< refill
+ r0 <- case result0 of
+ Done _ r -> return r
+ _ -> fail $ "failed to read " ++ show arg
start <- getCurrentTime
let loop !n r
| n >= count = return ()
| otherwise = {-# SCC "loop" #-} do
- case result of
- Done _ r -> rnf (encode r) `seq` loop (n+1) r
- _ -> error $ "failed to read " ++ show arg
- loop 0 r
+ rnf (encode r) `seq` loop (n+1) r
+ loop 0 r0
delta <- flip diffUTCTime start `fmap` getCurrentTime
let rate = fromIntegral count / realToFrac delta :: Double
putStrLn $ " " ++ show delta
- putStrLn $ " " ++ show (round rate) ++ " per second"
+ putStrLn $ " " ++ show (round rate :: Int) ++ " per second"
View
14 benchmarks/CompareWithJSON.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
import Blaze.ByteString.Builder (toLazyByteString)
@@ -6,9 +7,16 @@ import Control.DeepSeq (NFData(rnf))
import Criterion.Main
import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as BL
-import qualified Data.ByteString.Lazy.Internal as BL
import qualified Text.JSON as J
+#if !MIN_VERSION_bytestring(0,10,0)
+import qualified Data.ByteString.Lazy.Internal as BL
+
+instance NFData BL.ByteString where
+ rnf (BL.Chunk _ bs) = rnf bs
+ rnf BL.Empty = ()
+#endif
+
instance (NFData v) => NFData (J.JSObject v) where
rnf o = rnf (J.fromJSObject o)
@@ -20,10 +28,6 @@ instance NFData J.JSValue where
rnf (J.JSArray lst) = rnf lst
rnf (J.JSObject o) = rnf o
-instance NFData BL.ByteString where
- rnf (BL.Chunk _ bs) = rnf bs
- rnf BL.Empty = ()
-
decodeJ :: String -> J.JSValue
decodeJ s =
case J.decodeStrict s of

0 comments on commit aaed056

Please sign in to comment.
Something went wrong with that request. Please try again.