Skip to content
Snippets Groups Projects
Commit 1bc24281 authored by Simon Marlow's avatar Simon Marlow
Browse files

add chan, a simple Chan performance benchmark

parent d665bb10
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment