-
Notifications
You must be signed in to change notification settings - Fork 4
/
Time.hs
90 lines (85 loc) · 3.04 KB
/
Time.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main (main) where
import Control.DeepSeq
import Control.Monad
import Criterion.Main
import Criterion.Types
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as L
import qualified Data.Csv
import qualified Data.CSV.Conduit
import qualified Data.Sv
import qualified Data.Sv.Decode
import Data.Vector (Vector)
import System.Directory
import qualified Text.CSV
import qualified Text.CSV.Lazy.ByteString
import qualified Text.Parsec.Error
main :: IO ()
main = do
let fp = "out.csv"
exists <- doesFileExist fp
when exists (removeFile fp)
defaultMainWith
defaultConfig {csvFile = Just fp}
[ bgroup
"file (time)"
[ bench
"cassava/decode/Vector ByteString"
(nfIO
(do r <-
fmap (Data.Csv.decode Data.Csv.HasHeader) (L.readFile infp) :: IO (Either String (Vector (Vector ByteString)))
case r of
Left _ -> error "Unexpected parse error"
Right v -> pure v))
, bench
"cassava/decode/[ByteString]"
(nfIO
(do r <-
fmap (Data.Csv.decode Data.Csv.HasHeader) (L.readFile infp) :: IO (Either String (Vector [ByteString]))
case r of
Left _ -> error "Unexpected parse error"
Right v -> pure v))
, bench
"lazy-csv/parseCsv/[ByteString]"
(nfIO
(do r <- fmap Text.CSV.Lazy.ByteString.parseCSV (L.readFile infp)
pure $
Text.CSV.Lazy.ByteString.fromCSVTable $
Text.CSV.Lazy.ByteString.csvTableFull r))
, bench
"sv/Data.Sv/parseDecodeFromFile"
(nfIO
(Data.Sv.parseDecodeFromFile
Data.Sv.Decode.row
Data.Sv.defaultParseOptions
infp))
, bench
"csv-conduit/readCSVFile/[ByteString]"
(nfIO
(Data.CSV.Conduit.readCSVFile
Data.CSV.Conduit.defCSVSettings
infp :: IO (Vector [ByteString])))
, bench
"csv-conduit/readCSVFile/Vector ByteString"
(nfIO
(Data.CSV.Conduit.readCSVFile
Data.CSV.Conduit.defCSVSettings
infp :: IO (Vector (Vector ByteString))))
, bench
"csv-conduit/readCSVFile/[String]"
(nfIO
(Data.CSV.Conduit.readCSVFile
Data.CSV.Conduit.defCSVSettings
infp :: IO (Vector [String])))
, bench
"csv/Text.CSV/parseCSVFromFile"
(nfIO (Text.CSV.parseCSVFromFile infp))
]
]
-- | We don't need to force error messages, the test suite only parses
-- valid CSV files.
instance NFData Text.Parsec.Error.ParseError where
rnf _ = error "Unexpected parse error."
infp :: FilePath
infp = "in.csv"