summaryrefslogtreecommitdiff
path: root/bench/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'bench/Main.hs')
-rw-r--r--bench/Main.hs45
1 files changed, 22 insertions, 23 deletions
diff --git a/bench/Main.hs b/bench/Main.hs
index 024d4d93..97f97425 100644
--- a/bench/Main.hs
+++ b/bench/Main.hs
@@ -1,33 +1,32 @@
1{-# LANGUAGE OverloadedStrings #-} 1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE MultiParamTypeClasses #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
2module Main (main) where 4module Main (main) where
3
4import Control.Monad 5import Control.Monad
5import Data.ByteString (ByteString) 6import Control.Monad.Reader
6import qualified Data.ByteString as B
7import Criterion.Main 7import Criterion.Main
8import Data.ByteString as BS
8import Network.KRPC 9import Network.KRPC
9import Network.Socket
10 10
11instance KRPC ByteString ByteString where
12 method = "echo"
11 13
12addr :: RemoteAddr 14echo :: Handler IO
13addr = SockAddrInet 6000 0 15echo = handler $ \ _ bs -> return (bs :: ByteString)
14 16
15echo :: Method ByteString ByteString 17addr :: SockAddr
16echo = method "echo" ["x"] ["x"] 18addr = SockAddrInet 6000 (256 * 256 * 256 + 127)
17 19
18main :: IO () 20main :: IO ()
19main = withRemote $ \remote -> do { 21main = withManager addr [echo] $ \ m -> (`runReaderT` m) $ do
20 ; let sizes = [10, 100, 1000, 10000, 16 * 1024] 22 listen
21 ; let repetitions = [1, 10, 100, 1000] 23 liftIO $ defaultMain (benchmarks m)
22 ; let params = [(r, s) | r <- repetitions, s <- sizes]
23 ; let benchmarks = map (uncurry (mkbench_ remote)) params
24 ; defaultMain benchmarks
25 }
26 where 24 where
27 mkbench_ re r n = bench (show r ++ "/" ++ show n) $ nfIO $ 25 sizes = [10, 100, 1000, 10000, 16 * 1024]
28 replicateM r $ call_ re addr echo (B.replicate n 0) 26 repetitions = [1, 10, 100, 1000]
29 27 benchmarks m = [mkbench m r s | r <- repetitions, s <- sizes]
30{- 28 where
31 forM_ [1..] $ const $ do 29 mkbench m r n =
32 async addr myconcat (replicate 100 [1..10]) 30 bench (show r ++ "times" ++ "/" ++ show n ++ "bytes") $ nfIO $
33-} 31 replicateM r $
32 runReaderT (query addr (BS.replicate n 0)) m