Commit 1bc24281 authored by Simon Marlow's avatar Simon Marlow

add chan, a simple Chan performance benchmark

parent d665bb10
......@@ -8,7 +8,8 @@ SUBDIRS = \
threads001 \
threads003 \
threads006 \
threads007
threads007 \
chan
# later:
# stm001
......
TOP = ../..
include $(TOP)/mk/boilerplate.mk
FAST_OPTS = 100000
NORM_OPTS = 5000000
SLOW_OPTS = 50000000
include $(TOP)/mk/target.mk
-- 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment