Last active
December 13, 2015 21:38
-
-
Save k0001/4978406 to your computer and use it in GitHub Desktop.
Simple pipes-network benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Monad | |
import Control.Proxy ((>->)) | |
import qualified Control.Proxy as P | |
import qualified Control.Proxy.Safe as P | |
import qualified Control.Proxy.Network.TCP as NT | |
import qualified Control.Proxy.Safe.Network.TCP as NTS | |
import qualified Network.Socket.ByteString as NSB (recv) | |
import qualified Data.ByteString as B | |
import System.Environment (getArgs, getProgName) | |
host = "127.0.0.1" | |
port = "7000" | |
bufsize = 4096 :: Int | |
-- | Repeatedly consumes input and does nothing with it. | |
nullConsumer :: (Monad m, P.Proxy p) => () -> P.Consumer p a m r | |
nullConsumer () = P.runIdentityP . forever $ do | |
a <- P.request () | |
return $ a `seq` undefined -- not sure if this is needed, but just in case. | |
runRawIO = do | |
NT.withClient host port $ \(csock,_) -> do | |
let loop = do | |
bs <- NSB.recv csock bufsize | |
if B.null bs then return () else loop | |
loop | |
runPipeSafeIO = do | |
let sess = NTS.clientP bufsize host port >-> nullConsumer | |
P.runSafeIO . P.runProxy . P.runEitherK $ sess | |
runPipeIO = do | |
NT.withClient host port $ \(csock,_) -> do | |
P.runProxy $ NT.socketP bufsize csock >-> nullConsumer | |
main = do | |
args <- getArgs | |
case args of | |
["RawIO"] -> runRawIO | |
["PipeIO"] -> runPipeIO | |
["PipeSafeIO"] -> runPipeSafeIO | |
_ -> putStrLn =<< usage | |
where | |
usage = do | |
progName <- getProgName | |
return $ "Usage: " ++ progName ++ " [RawIO|PipeIO|PipeSafeIO]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The folling examples were compiled against pipes-network 2e45af859b1286740ef27533fa7b8b7bf9e18a12 | |
From /proc/cpuinfo: CPU model name: Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz | |
uname -a: Linux qx 3.2.0-4-amd64 #1 SMP Debian 3.2.35-2 x86_64 GNU/Linux | |
Compiled with: ghc --make -O2 ex1.hs | |
k@qx:pts/11 ~/q/pipes-network.git 0 % nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' &; (sleep .1 && ./ex1 RawIO) | |
[1] 22901 | |
1000000+0 records in | |
1000000+0 records out | |
4096000000 bytes (4.1 GB) copied, 4.40759 s, 929 MB/s | |
0.13user 3.03system 0:04.40elapsed 71%CPU (0avgtext+0avgdata 880maxresident)k | |
0inputs+0outputs (0major+264minor)pagefaults 0swaps | |
[1] + done nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' | |
k@qx:pts/11 ~/q/pipes-network.git 0 % nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' &; (sleep .1 && ./ex1 PipeIO) | |
[1] 22935 | |
1000000+0 records in | |
1000000+0 records out | |
4096000000 bytes (4.1 GB) copied, 5.62204 s, 729 MB/s | |
0.18user 3.14system 0:05.62elapsed 59%CPU (0avgtext+0avgdata 876maxresident)k | |
0inputs+0outputs (0major+263minor)pagefaults 0swaps | |
[1] + done nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' | |
k@qx:pts/11 ~/q/pipes-network.git 0 % nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' &; (sleep .1 && ./ex1 PipeSafeIO) | |
[1] 22960 | |
1000000+0 records in | |
1000000+0 records out | |
4096000000 bytes (4.1 GB) copied, 9.06011 s, 452 MB/s | |
0.11user 2.66system 0:09.06elapsed 30%CPU (0avgtext+0avgdata 876maxresident)k | |
0inputs+0outputs (0major+264minor)pagefaults 0swaps | |
[1] + done nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' | |
Compiled with: ghc --make -O0 | |
k@qx:pts/11 ~/q/pipes-network.git 0 % nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' &; (sleep .1 && ./ex1 RawIO) | |
[1] 23219 | |
1000000+0 records in | |
1000000+0 records out | |
4096000000 bytes (4.1 GB) copied, 4.96993 s, 824 MB/s | |
0.14user 3.05system 0:04.97elapsed 64%CPU (0avgtext+0avgdata 880maxresident)k | |
0inputs+0outputs (0major+265minor)pagefaults 0swaps | |
[1] + done nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' | |
k@qx:pts/11 ~/q/pipes-network.git 0 % nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' &; (sleep .1 && ./ex1 PipeIO) | |
[1] 23237 | |
1000000+0 records in | |
1000000+0 records out | |
4096000000 bytes (4.1 GB) copied, 6.32781 s, 647 MB/s | |
0.17user 3.02system 0:06.33elapsed 50%CPU (0avgtext+0avgdata 876maxresident)k | |
0inputs+0outputs (0major+263minor)pagefaults 0swaps | |
[1] + done nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' | |
k@qx:pts/11 ~/q/pipes-network.git 0 % nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' &; (sleep .1 && ./ex1 PipeSafeIO) | |
[1] 23258 | |
1000000+0 records in | |
1000000+0 records out | |
4096000000 bytes (4.1 GB) copied, 9.80194 s, 418 MB/s | |
0.11user 2.73system 0:09.80elapsed 29%CPU (0avgtext+0avgdata 884maxresident)k | |
0inputs+0outputs (0major+265minor)pagefaults 0swaps | |
[1] + done nc -l -p 7000 -c 'time /bin/dd if=/dev/zero bs=4096 count=1000000' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment