@@ -5,12 +5,12 @@ import Network.Transport.TCP (mkTransport, TCPConfig (..))
55
66import Control.Monad (forever, replicateM_)
77import Criterion.Main (Benchmark, bench, defaultMain, nfIO)
8−import Data.Binary
8+import Data.Serialize
99import Data.Maybe (fromJust)
1010import Data.Int
1111import System.Environment (getArgs, withArgs)
1212
13−import qualified Data.ByteString.Lazy.Char8 as BS
13+import qualified Data.ByteString as BS
1414
1515-- | This performs a ping benchmark on the TCP transport. This can be
1616-- compiled using:
@@ -77,16 +77,17 @@ pong targetEndPing sourceEndPong = do
7777-- | The effect of `ping sourceEndPing targetEndPong n` is to send the number
7878-- `n` using `sourceEndPing`, and to then receive the a number from
7979-- `targetEndPong`, which is then returned.
80−ping :: SourceEnd -> TargetEnd -> IO Int64
81−ping sourceEndPing targetEndPong = do
82− send sourceEndPing [BS.empty]
80+ping :: SourceEnd -> TargetEnd -> Int64 -> IO Int64
81+ping sourceEndPing targetEndPong n = do
82+ send sourceEndPing [encode n]
8383 [bs] <- receive targetEndPong
84− return $ decode bs
84+ let (Right n) = decode bs
85+ return $! n
8586
8687-- | The effect of `benchPing sourceEndPing targetEndPong n` is to send
8788-- `n` pings down `sourceEndPing` using the `ping` function. The time
8889-- taken is benchmarked.
8990benchPing :: SourceEnd -> TargetEnd -> Int64 -> Benchmark
9091benchPing sourceEndPing targetEndPong n = bench "PingTransport" $
91− nfIO (replicateM_ (fromIntegral n) (ping sourceEndPing targetEndPong))
92+ nfIO (replicateM_ (fromIntegral n) (ping sourceEndPing targetEndPong 42))
9293