Permalink
Browse files

More benchmarkery: try out the json library.

It performs surprisingly well!

--HG--
rename : benchmarks/ParseFile.hs => benchmarks/AesonParse.hs
rename : benchmarks/ParseFile.hs => benchmarks/JsonParse.hs
  • Loading branch information...
1 parent 3bb5f85 commit 3568e5ef42c9d47c13a243d7ef91350b5d33dc87 @bos committed Jan 27, 2011
Showing with 43 additions and 0 deletions.
  1. +8 −0 aeson.cabal
  2. 0 benchmarks/{ParseFile.hs → AesonParse.hs}
  3. +35 −0 benchmarks/JsonParse.hs
View
@@ -42,6 +42,10 @@ description:
extra-source-files:
README.markdown
+ benchmarks/AesonParse.hs
+ benchmarks/EncodeFile.hs
+ benchmarks/JsonParse.hs
+ benchmarks/ReadFile.hs
flag developer
description: operate in developer mode
@@ -75,3 +79,7 @@ library
source-repository head
type: git
location: http://github.com/mailrank/aeson
+
+source-repository head
+ type: mercurial
+ location: http://bitbucket.org/bos/aeson
File renamed without changes.
View
@@ -0,0 +1,35 @@
+{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}
+
+import Control.DeepSeq
+import Control.Exception
+import Control.Monad
+import Text.JSON
+import Data.Time.Clock
+import System.Environment (getArgs)
+import System.IO
+import qualified Data.ByteString as B
+
+instance NFData JSValue where
+ rnf JSNull = ()
+ rnf (JSBool b) = rnf b
+ rnf (JSRational b r) = rnf b `seq` rnf r `seq` ()
+ rnf (JSString s) = rnf (fromJSString s)
+ rnf (JSArray vs) = rnf vs
+ rnf (JSObject kvs) = rnf (fromJSObject kvs)
+
+main = do
+ (cnt:args) <- getArgs
+ let count = read cnt :: Int
+ forM_ args $ \arg -> do
+ putStrLn $ arg ++ ":"
+ start <- getCurrentTime
+ let loop !good !bad
+ | good+bad >= count = return (good, bad)
+ | otherwise = do
+ s <- readFile arg
+ case decodeStrict s of
+ Ok (v::JSValue) -> loop (good+1) 0
+ _ -> loop 0 (bad+1)
+ (good, _) <- loop 0 0
+ end <- getCurrentTime
+ putStrLn $ " " ++ show good ++ " good, " ++ show (diffUTCTime end start)

0 comments on commit 3568e5e

Please sign in to comment.