on master help sign in
add benchmark
commit711dee15770c773acf174a6240e019c3c52c3a62 authorAgentM <agentm@themactionfaction.com> dateSun 4 Oct 2020, 13:39 (6 years ago) parent1f4adb8
2 files changed+59−1
bench/Basic.hs+48 curryer.cabal+11−1
bench/Basic.hsnew file+48
@@ -0,0 +1,48 @@
1+{-# LANGUAGE DerivingStrategies, DeriveGeneric, DerivingVia #-}
2+import Network.RPC.Curryer.Server
3+import Network.RPC.Curryer.Client
4+import Criterion.Main
5+import GHC.Generics
6+import Control.Concurrent.MVar
7+import Network.Socket (SockAddr(..))
8+import Codec.Winery
9+import Control.Concurrent.Async
10+import Control.Concurrent
11+import Control.Monad
12+
13+main :: IO ()
14+main = do
15+ --start server shared across benchmarks- gather stats on round-trip requests-responses
16+ portReadyMVar <- newEmptyMVar
17+ server <- async (serve (pure Nothing) benchmarkServerMessageHandler localHostAddr 0 (Just portReadyMVar))
18+ --wait for server to be ready
19+ (SockAddrInet port _) <- takeMVar portReadyMVar
20+ clientConn <- connect (const (pure ())) localHostAddr port
21+
22+ _ <- syncWaitRequest clientConn 100
23+ defaultMain [bgroup "wait sync" [bench "100 ms" (nfIO $ syncWaitRequest clientConn 100)]]
24+
25+ putStrLn "benchmark complete"
26+ close clientConn
27+ cancel server
28+
29+data BenchRequest = WaitMillisecondsReq Int
30+ deriving (Generic, Show)
31+ deriving Serialise via WineryVariant BenchRequest
32+
33+data BenchResponse = WaitMillisecondsResp
34+ deriving (Generic, Show, Eq)
35+ deriving Serialise via WineryVariant BenchResponse
36+
37+benchmarkServerMessageHandler :: BenchRequest -> IO (HandlerResponse BenchResponse)
38+benchmarkServerMessageHandler (WaitMillisecondsReq ms) = do
39+ threadDelay (1000 * ms)
40+ pure (HandlerResponse WaitMillisecondsResp)
41+
42+--perform 10000 small synchronous requests
43+syncWaitRequest :: Connection BenchResponse -> Int -> IO Int
44+syncWaitRequest conn ms = do
45+ ret <- call conn (WaitMillisecondsReq ms)
46+ when (ret /= Right WaitMillisecondsResp) (error "ret failed")
47+ pure ms
48+
curryer.cabal+11−1
@@ -52,4 +52,14 @@ Test-Suite test
5252 , winery
5353 , network
5454 , async
55− other-modules: Curryer.Test.Basic
55+ other-modules: Curryer.Test.Basic
56+
57+Benchmark perf
58+ Default-Language: Haskell2010
59+ Default-Extensions: OverloadedStrings
60+ Build-Depends: base, criterion, curryer, network, winery, async
61+ Main-Is: Basic.hs
62+ Type: exitcode-stdio-1.0
63+ GHC-Options: -Wall -threaded -rtsopts
64+ HS-Source-Dirs: ./bench
65+