on master help sign in
More benchmarkery: try out the json library.

It performs surprisingly well!

commit7a011586d5585182cd58a562cc8391fae54f01fd authorBryan O'Sullivan <bos@mailrank.com> dateWed 26 Jan 2011, 18:38 (16 years ago) parentb4d4b90
3 files changed+43
aeson.cabal+8 benchmarks/ParseFile.hs → benchmarks/AesonParse.hs benchmarks/JsonParse.hs+35
aeson.cabal+8
@@ -42,6 +42,10 @@ description:
4242
4343extra-source-files:
4444 README.markdown
45+ benchmarks/AesonParse.hs
46+ benchmarks/EncodeFile.hs
47+ benchmarks/JsonParse.hs
48+ benchmarks/ReadFile.hs
4549
4650flag developer
4751 description: operate in developer mode
@@ -75,3 +79,7 @@ library
7579source-repository head
7680 type: git
7781 location: http://github.com/mailrank/aeson
82+
83+source-repository head
84+ type: mercurial
85+ location: http://bitbucket.org/bos/aeson
benchmarks/ParseFile.hs → benchmarks/AesonParse.hsrenamed

The content is the same.

benchmarks/JsonParse.hsnew file+35
@@ -0,0 +1,35 @@
1+{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}
2+
3+import Control.DeepSeq
4+import Control.Exception
5+import Control.Monad
6+import Text.JSON
7+import Data.Time.Clock
8+import System.Environment (getArgs)
9+import System.IO
10+import qualified Data.ByteString as B
11+
12+instance NFData JSValue where
13+ rnf JSNull = ()
14+ rnf (JSBool b) = rnf b
15+ rnf (JSRational b r) = rnf b `seq` rnf r `seq` ()
16+ rnf (JSString s) = rnf (fromJSString s)
17+ rnf (JSArray vs) = rnf vs
18+ rnf (JSObject kvs) = rnf (fromJSObject kvs)
19+
20+main = do
21+ (cnt:args) <- getArgs
22+ let count = read cnt :: Int
23+ forM_ args $ \arg -> do
24+ putStrLn $ arg ++ ":"
25+ start <- getCurrentTime
26+ let loop !good !bad
27+ | good+bad >= count = return (good, bad)
28+ | otherwise = do
29+ s <- readFile arg
30+ case decodeStrict s of
31+ Ok (v::JSValue) -> loop (good+1) 0
32+ _ -> loop 0 (bad+1)
33+ (good, _) <- loop 0 0
34+ end <- getCurrentTime
35+ putStrLn $ " " ++ show good ++ " good, " ++ show (diffUTCTime end start)