forked from snoyberg/conduit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.hs
52 lines (45 loc) · 1.34 KB
/
bench.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
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Lazy as L
import qualified Codec.Compression.GZip as GZip
import Criterion.Main
import qualified Data.Conduit as C
import qualified Data.Conduit.Binary as CB
import qualified Data.Conduit.Zlib as CZ
import qualified Data.Enumerator as E
import qualified Data.Enumerator.Binary as EB
import qualified Codec.Zlib.Enum as EZ
import qualified System.IO as SIO
filePath :: FilePath
filePath = "sample.gz"
lazyIO :: IO ()
lazyIO = do
compressed <- L.readFile filePath
L.writeFile "tmp" $ GZip.decompress compressed
conduits1 :: IO ()
conduits1 = C.runResourceT
$ CB.sourceFile "sample.gz"
C.$$ CZ.ungzip
C.=$ CB.sinkFile "tmp"
conduits2 :: IO ()
conduits2 = C.runResourceT
$ CB.sourceFile "sample.gz"
C.$= CZ.ungzip
C.$$ CB.sinkFile "tmp"
enumerator1 :: IO ()
enumerator1 = SIO.withBinaryFile "tmp" SIO.WriteMode $ \h -> E.run_
$ EB.enumFile filePath
E.$$ EZ.ungzip
E.=$ EB.iterHandle h
enumerator2 :: IO ()
enumerator2 = SIO.withBinaryFile "tmp" SIO.WriteMode $ \h -> E.run_
$ EB.enumFile filePath
E.$= EZ.ungzip
E.$$ EB.iterHandle h
main :: IO ()
main = defaultMain
[ bench "conduits1" conduits1
, bench "conduits2" conduits2
, bench "enumerator1" enumerator1
, bench "enumerator2" enumerator2
, bench "lazyIO" lazyIO
]