Permalink
Browse files

Add benchmark that compares to csv-lazy

  • Loading branch information...
1 parent 6ab7c28 commit ead0ad2391cbd84bbcc6c4ad35cee413d09382d1 @tibbe tibbe committed Feb 25, 2013
Showing with 20 additions and 0 deletions.
  1. +18 −0 benchmarks/Benchmarks.hs
  2. +2 −0 cassava.cabal
@@ -5,17 +5,20 @@
module Main ( main ) where
import Control.Applicative
+import Control.DeepSeq
import Criterion.Main
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.HashMap.Strict as HM
import Control.Monad (mzero)
import Data.Text (Text)
+import qualified Text.CSV.Lazy.ByteString as LazyCsv
import Data.Vector (Vector)
import qualified Data.Vector as V
import Data.Csv
+import qualified Data.Csv.Streaming as Streaming
data President = President
{ presidency :: !Int
@@ -77,6 +80,17 @@ fromStrict s = BL.fromChunks [s]
type BSHashMap a = HM.HashMap B.ByteString a
+instance NFData LazyCsv.CSVField where
+ rnf LazyCsv.CSVField {} = ()
+ rnf LazyCsv.CSVFieldError {} = ()
+
+instance NFData LazyCsv.CSVError where
+ rnf (LazyCsv.IncorrectRow !_ !_ !_ xs) = rnf xs
+ rnf (LazyCsv.BlankLine _ _ _ field) = rnf field
+ rnf (LazyCsv.FieldError field) = rnf field
+ rnf (LazyCsv.DuplicateHeader _ s) = rnf s
+ rnf LazyCsv.NoData = ()
+
main :: IO ()
main = do
!csvData <- fromStrict `fmap` B.readFile "benchmarks/presidents.csv"
@@ -103,6 +117,10 @@ main = do
[ bench "presidents/with conversion" $ whnf (encodeByName hdr) presidentsN
]
]
+ , bgroup "comparison"
+ [ bench "cassava" $ nf idDecode csvData
+ , bench "lazy-csv" $ nf LazyCsv.parseCSV csvData
+ ]
]
where
decodePresidents :: BL.ByteString -> Either String (Vector President)
View
@@ -80,6 +80,8 @@ Benchmark benchmarks
bytestring,
cassava,
criterion,
+ deepseq,
+ lazy-csv,
text,
unordered-containers,
vector

0 comments on commit ead0ad2

Please sign in to comment.