hs-tls/core/Benchmarks/Benchmarks.hs

56 lines
1.9 KiB
Haskell
Raw Normal View History

2013-07-21 07:57:56 +00:00
{-# LANGUAGE BangPatterns #-}
2013-07-13 07:04:26 +00:00
module Main where
import Connection
2013-07-21 07:57:56 +00:00
import Certificate
import PubKey
2013-07-13 07:04:26 +00:00
import Criterion.Main
2013-07-21 07:57:56 +00:00
import Control.Concurrent.Chan
import Network.TLS
import Data.X509
2013-07-13 07:04:26 +00:00
2013-07-21 07:57:56 +00:00
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
2013-07-13 07:04:26 +00:00
2013-07-21 07:57:56 +00:00
recvDataNonNull ctx = recvData ctx >>= \l -> if B.null l then recvDataNonNull ctx else return l
getParams connectVer cipher = (cParams, sParams)
where sParams = defaultParamsServer
{ pAllowedVersions = [connectVer]
, pCiphers = [cipher]
, pCredentials = Credentials [ (CertificateChain [simpleX509 $ PubKeyRSA pubKey], PrivKeyRSA privKey) ]
2013-07-21 07:57:56 +00:00
}
cParams = defaultParamsClient
{ pAllowedVersions = [connectVer]
, pCiphers = [cipher]
}
(pubKey, privKey) = getGlobalRSAPair
runTLSPipe params tlsServer tlsClient d name = bench name $ do
(startQueue, resultQueue) <- establishDataPipe params tlsServer tlsClient
writeChan startQueue d
readChan resultQueue
bench1 params !d name = runTLSPipe params tlsServer tlsClient d name
where tlsServer ctx queue = do
handshake ctx
d <- recvDataNonNull ctx
writeChan queue d
return ()
tlsClient queue ctx = do
handshake ctx
d <- readChan queue
sendData ctx (L.fromChunks [d])
bye ctx
return ()
main = defaultMain
2013-07-21 08:33:23 +00:00
[ bgroup "connection"
-- not sure the number actually make sense for anything. improve ..
[ bench1 (getParams SSL3 blockCipher) (B.replicate 256 0) "SSL3-256 bytes"
, bench1 (getParams TLS10 blockCipher) (B.replicate 256 0) "TLS10-256 bytes"
, bench1 (getParams TLS11 blockCipher) (B.replicate 256 0) "TLS11-256 bytes"
, bench1 (getParams TLS12 blockCipher) (B.replicate 256 0) "TLS12-256 bytes"
]
2013-07-21 07:57:56 +00:00
]