summaryrefslogtreecommitdiff
path: root/bench/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'bench/Main.hs')
-rw-r--r--bench/Main.hs37
1 files changed, 35 insertions, 2 deletions
diff --git a/bench/Main.hs b/bench/Main.hs
index a7b937ff..d021e03e 100644
--- a/bench/Main.hs
+++ b/bench/Main.hs
@@ -1,14 +1,28 @@
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE MultiParamTypeClasses #-}
1{-# OPTIONS -fno-warn-orphans #-} 3{-# OPTIONS -fno-warn-orphans #-}
2module Main (main) where 4module Main (main) where
3 5
4import Control.DeepSeq 6import Control.DeepSeq
5import Criterion.Main
6import Network 7import Network
8import Control.Monad
9import Control.Monad.Logger
10import Control.Monad.Reader
11import Criterion.Main
12import Data.ByteString as BS
13import Network.KRPC
14
7 15
8import Network.BitTorrent.Exchange.Protocol as BT 16import Network.BitTorrent.Exchange.Protocol as BT
9import Data.Torrent.Block as BT 17import Data.Torrent.Block as BT
10import Data.Torrent.Bitfield as BT 18import Data.Torrent.Bitfield as BT
11 19
20instance KRPC ByteString ByteString where
21 method = "echo"
22
23instance MonadLogger IO where
24 monadLoggerLog _ _ _ _ = return ()
25
12 26
13instance NFData PortNumber where 27instance NFData PortNumber where
14 rnf = rnf . (fromIntegral :: PortNumber -> Int) 28 rnf = rnf . (fromIntegral :: PortNumber -> Int)
@@ -38,5 +52,24 @@ decodeMessages :: ByteString -> Either String [Message]
38decodeMessages = runGet (many get) 52decodeMessages = runGet (many get)
39-} 53-}
40 54
55echo :: Handler IO
56echo = handler $ \ _ bs -> return (bs :: ByteString)
57
58addr :: SockAddr
59addr = SockAddrInet 6000 (256 * 256 * 256 + 127)
60
61-- main :: IO ()
62-- main = defaultMain []
41main :: IO () 63main :: IO ()
42main = defaultMain [] 64main = withManager def addr [echo] $ \ m -> (`runReaderT` m) $ do
65 listen
66 liftIO $ defaultMain (benchmarks m)
67 where
68 sizes = [10, 100, 1000, 10000, 16 * 1024]
69 repetitions = [1, 10, 100, 1000]
70 benchmarks m = [mkbench m r s | r <- repetitions, s <- sizes]
71 where
72 mkbench action r n =
73 bench (show r ++ "times" ++ "/" ++ show n ++ "bytes") $ nfIO $
74 replicateM r $
75 runReaderT (query addr (BS.replicate n 0)) action