Add a benchmark

The benchmark tests a single heavily contended counter.
This commit is contained in:
Johan Tibell 2014-04-08 16:01:28 +02:00
parent 61228d0ac2
commit 7f11142c89
2 changed files with 36 additions and 0 deletions

24
benchmarks/Benchmarks.hs Normal file
View file

@ -0,0 +1,24 @@
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
-- | Perform 100,000 atomic increments using 100 concurrent writers.
module Main where
import Control.Concurrent
import Control.Monad
import System.Remote.Counter
import System.Remote.Monitoring
main :: IO ()
main = do
handle <- forkServer "localhost" 8000
counter <- getCounter "iterations" handle
locks <- replicateM n newEmptyMVar
mapM_ (forkIO . work counter iters) locks
mapM_ takeMVar locks
where
n = 100
iters = 100000
work :: Counter -> Int -> MVar () -> IO ()
work !_ 0 !lock = putMVar lock ()
work counter i lock = inc counter >> work counter (i - 1) lock

View file

@ -20,6 +20,7 @@ data-files: assets/index.html assets/monitor.js assets/monitor.css
extra-source-files: LICENSE.icons LICENSE.javascript README.md extra-source-files: LICENSE.icons LICENSE.javascript README.md
assets/jquery-1.6.4.js assets/jquery.flot.js assets/jquery-1.6.4.js assets/jquery.flot.js
examples/Basic.hs CHANGES.md examples/Basic.hs CHANGES.md
cabal-version: >= 1.8
library library
exposed-modules: exposed-modules:
@ -52,6 +53,17 @@ library
ghc-options: -Wall ghc-options: -Wall
benchmark benchmarks
hs-source-dirs: benchmarks
main-is: Benchmarks.hs
type: exitcode-stdio-1.0
build-depends:
base,
ekg
ghc-options: -O2 -threaded -Wall
source-repository head source-repository head
type: git type: git
location: https://github.com/tibbe/ekg.git location: https://github.com/tibbe/ekg.git