Skip to content

Commit

Permalink
Add benchmark that compares to csv-lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbe committed Feb 25, 2013
1 parent 6ab7c28 commit ead0ad2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions benchmarks/Benchmarks.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cassava.cabal
Expand Up @@ -80,6 +80,8 @@ Benchmark benchmarks
bytestring,
cassava,
criterion,
deepseq,
lazy-csv,
text,
unordered-containers,
vector
Expand Down

0 comments on commit ead0ad2

Please sign in to comment.