Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
Update benchmarks.
Browse files Browse the repository at this point in the history
Fixed and updated benchmarks to the latest conduit and pipes-extra.

Benchmarks are now integrated in cabal, so you can run them with
something like:

    cabal configure --enable-benchmarks
    cabal build
    cabal bench
  • Loading branch information
pcapriotti committed Jun 3, 2012
1 parent d2266fd commit 143b53b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 37 deletions.
31 changes: 0 additions & 31 deletions Benchmarks/general.hs

This file was deleted.

Binary file removed Benchmarks/simple
Binary file not shown.
File renamed without changes.
21 changes: 21 additions & 0 deletions bench/general.hs
@@ -0,0 +1,21 @@
import Criterion.Main
import qualified Data.Conduit as C
import qualified Data.Conduit.List as CL
import qualified Data.Conduit.Binary as CB

import Control.Pipe.Binary
import Control.Pipe.Combinators
import Control.Pipe

testFile :: FilePath
testFile = "bench/general.hs"

main :: IO ()
main = defaultMain
[ bench "bigsum-pipes" (whnfIO $ runPipe $ (mapM_ yield [1..1000 :: Int] >> return 0) >+> fold (+) 0)
, bench "bigsum-conduit" (whnfIO $ C.runResourceT $ CL.sourceList [1..1000 :: Int] C.$$ CL.fold (+) 0)
, bench "fileread-pipes" (whnfIO $ runPipe $ fileReader testFile >+> discard)
, bench "fileread-conduit" (whnfIO $ C.runResourceT $ CB.sourceFile testFile C.$$ CL.sinkNull)
, bench "map-pipes" (whnfIO $ runPipe $ (mapM_ yield [1..1000 :: Int] >> return 0) >+> pipe (+1) >+> fold (+) 0)
, bench "map-conduit" (whnfIO $ C.runResourceT $ CL.sourceList [1..1000 :: Int] C.$= CL.map (+ 1) C.$$ CL.fold (+) 0)
]
File renamed without changes.
1 change: 1 addition & 0 deletions Benchmarks/simple.hs → bench/simple.hs
@@ -1,6 +1,7 @@
import Criterion.Main

import Control.Monad
import Control.Monad.Trans.Class
import Control.Pipe
import System.IO

Expand Down
15 changes: 9 additions & 6 deletions Benchmarks/zlib.hs → bench/zlib.hs
Expand Up @@ -15,27 +15,30 @@ import qualified Control.Pipe.Binary as PB
import qualified Control.Pipe.Zlib as PZ

filePath :: FilePath
filePath = "sample.gz"
filePath = "bench/sample.gz"

tmpFile :: FilePath
tmpFile = "dist/build/autogen/bench-tmp"

lazyIO :: IO ()
lazyIO = do
compressed <- L.readFile filePath
L.writeFile "tmp" $ GZip.decompress compressed
L.writeFile tmpFile $ GZip.decompress compressed

conduits1 :: IO ()
conduits1 = C.runResourceT
$ CB.sourceFile filePath
C.$$ CZ.ungzip
C.=$ CB.sinkFile "tmp"
C.=$ CB.sinkFile tmpFile

conduits2 :: IO ()
conduits2 = C.runResourceT
$ CB.sourceFile filePath
C.$= CZ.ungzip
C.$$ CB.sinkFile "tmp"
C.$$ CB.sinkFile tmpFile

enumerator :: IO ()
enumerator = SIO.withBinaryFile "tmp" SIO.WriteMode $ \h -> E.run_
enumerator = SIO.withBinaryFile tmpFile SIO.WriteMode $ \h -> E.run_
$ EB.enumFile filePath
E.$$ EZ.ungzip
E.=$ EB.iterHandle h
Expand All @@ -44,7 +47,7 @@ pipes :: IO ()
pipes = runPipe
$ PB.fileReader filePath
>+> PZ.gunzip
>+> PB.fileWriter "tmp"
>+> PB.fileWriter tmpFile

main :: IO ()
main = defaultMain
Expand Down
36 changes: 36 additions & 0 deletions pipes-extra.cabal
Expand Up @@ -28,3 +28,39 @@ Library
Control.Pipe.PutbackPipe,
Control.Pipe.Tee,
Control.Pipe.Zip

benchmark bench-general
type: exitcode-stdio-1.0
hs-source-dirs: . bench
main-is: general.hs
build-depends: base == 4.*
, pipes-core == 0.1.*
, bytestring == 0.9.*
, transformers >= 0.2 && < 0.4
, conduit == 0.4.*
, criterion == 0.6.*

benchmark bench-simple
type: exitcode-stdio-1.0
hs-source-dirs: . bench
main-is: simple.hs
build-depends: base == 4.*
, pipes-core == 0.1.*
, transformers >= 0.2 && < 0.4
, criterion == 0.6.*

benchmark bench-zlib
type: exitcode-stdio-1.0
hs-source-dirs: . bench
main-is: zlib.hs
build-depends: base == 4.*
, pipes-core == 0.1.*
, pipes-zlib < 0.2
, bytestring == 0.9.*
, transformers >= 0.2 && < 0.4
, enumerator == 0.4.*
, zlib-enum == 0.2.*
, conduit == 0.4.*
, zlib-conduit == 0.4.*
, zlib == 0.5.*
, criterion == 0.6.*

0 comments on commit 143b53b

Please sign in to comment.