From 1bc2428103924c0af2a7eba5c6cc318c4eaa1ead Mon Sep 17 00:00:00 2001 From: Simon Marlow <marlowsd@gmail.com> Date: Thu, 8 Jul 2010 13:52:19 +0000 Subject: [PATCH] add chan, a simple Chan performance benchmark --- smp/Makefile | 3 ++- smp/chan/Makefile | 8 ++++++++ smp/chan/chan.hs | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 smp/chan/Makefile create mode 100644 smp/chan/chan.hs diff --git a/smp/Makefile b/smp/Makefile index d56eb535..d1cb29f2 100644 --- a/smp/Makefile +++ b/smp/Makefile @@ -8,7 +8,8 @@ SUBDIRS = \ threads001 \ threads003 \ threads006 \ - threads007 + threads007 \ + chan # later: # stm001 diff --git a/smp/chan/Makefile b/smp/chan/Makefile new file mode 100644 index 00000000..29bb5165 --- /dev/null +++ b/smp/chan/Makefile @@ -0,0 +1,8 @@ +TOP = ../.. +include $(TOP)/mk/boilerplate.mk + +FAST_OPTS = 100000 +NORM_OPTS = 5000000 +SLOW_OPTS = 50000000 + +include $(TOP)/mk/target.mk diff --git a/smp/chan/chan.hs b/smp/chan/chan.hs new file mode 100644 index 00000000..a3cef465 --- /dev/null +++ b/smp/chan/chan.hs @@ -0,0 +1,21 @@ +-- benchmarks communication on Chan +-- +-- This is a synthetic benchmark that is sensitive to scheduler +-- behaviour. In GHC 6.12 and earlier we triggered a context switch +-- shortly after waking up a thread, whereas in 6.14 and later we +-- stopped doing that. This benchmark performs worse with 6.14 +-- becauuse not doing the context switch allows a lot of data to build +-- up in the Chan, making GC expensive. + +import Control.Concurrent +import Control.Concurrent.Chan +import System.Environment +import Control.Monad + +main = do + [n] <- fmap (fmap read) getArgs + c <- newChan + m <- newEmptyMVar + a <- forkIO $ forM_ [1..n] $ \i -> writeChan c i + b <- forkIO $ do forM_ [1..n] $ \i -> readChan c; putMVar m () + takeMVar m -- GitLab