diff options
Diffstat (limited to 'bench')
-rw-r--r-- | bench/Main.hs | 37 |
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 #-} |
2 | module Main (main) where | 4 | module Main (main) where |
3 | 5 | ||
4 | import Control.DeepSeq | 6 | import Control.DeepSeq |
5 | import Criterion.Main | ||
6 | import Network | 7 | import Network |
8 | import Control.Monad | ||
9 | import Control.Monad.Logger | ||
10 | import Control.Monad.Reader | ||
11 | import Criterion.Main | ||
12 | import Data.ByteString as BS | ||
13 | import Network.KRPC | ||
14 | |||
7 | 15 | ||
8 | import Network.BitTorrent.Exchange.Protocol as BT | 16 | import Network.BitTorrent.Exchange.Protocol as BT |
9 | import Data.Torrent.Block as BT | 17 | import Data.Torrent.Block as BT |
10 | import Data.Torrent.Bitfield as BT | 18 | import Data.Torrent.Bitfield as BT |
11 | 19 | ||
20 | instance KRPC ByteString ByteString where | ||
21 | method = "echo" | ||
22 | |||
23 | instance MonadLogger IO where | ||
24 | monadLoggerLog _ _ _ _ = return () | ||
25 | |||
12 | 26 | ||
13 | instance NFData PortNumber where | 27 | instance NFData PortNumber where |
14 | rnf = rnf . (fromIntegral :: PortNumber -> Int) | 28 | rnf = rnf . (fromIntegral :: PortNumber -> Int) |
@@ -38,5 +52,24 @@ decodeMessages :: ByteString -> Either String [Message] | |||
38 | decodeMessages = runGet (many get) | 52 | decodeMessages = runGet (many get) |
39 | -} | 53 | -} |
40 | 54 | ||
55 | echo :: Handler IO | ||
56 | echo = handler $ \ _ bs -> return (bs :: ByteString) | ||
57 | |||
58 | addr :: SockAddr | ||
59 | addr = SockAddrInet 6000 (256 * 256 * 256 + 127) | ||
60 | |||
61 | -- main :: IO () | ||
62 | -- main = defaultMain [] | ||
41 | main :: IO () | 63 | main :: IO () |
42 | main = defaultMain [] | 64 | main = 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 | ||