From 7f11142c89c276fb54fc89e43882fad18fd386a7 Mon Sep 17 00:00:00 2001 From: Johan Tibell Date: Tue, 8 Apr 2014 16:01:28 +0200 Subject: [PATCH] Add a benchmark The benchmark tests a single heavily contended counter. --- benchmarks/Benchmarks.hs | 24 ++++++++++++++++++++++++ ekg.cabal | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 benchmarks/Benchmarks.hs diff --git a/benchmarks/Benchmarks.hs b/benchmarks/Benchmarks.hs new file mode 100644 index 0000000..eb10220 --- /dev/null +++ b/benchmarks/Benchmarks.hs @@ -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 diff --git a/ekg.cabal b/ekg.cabal index ddfdc4e..2a06de9 100644 --- a/ekg.cabal +++ b/ekg.cabal @@ -20,6 +20,7 @@ data-files: assets/index.html assets/monitor.js assets/monitor.css extra-source-files: LICENSE.icons LICENSE.javascript README.md assets/jquery-1.6.4.js assets/jquery.flot.js examples/Basic.hs CHANGES.md +cabal-version: >= 1.8 library exposed-modules: @@ -52,6 +53,17 @@ library 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 type: git location: https://github.com/tibbe/ekg.git