Repository : ssh://darcs.haskell.org//srv/darcs/packages/stm On branch : master
http://hackage.haskell.org/trac/ghc/changeset/a143a9679aa845b04d825ebfbea6c17034ea9f68 >--------------------------------------------------------------- commit a143a9679aa845b04d825ebfbea6c17034ea9f68 Author: Simon Marlow <[email protected]> Date: Wed Jul 4 11:20:45 2012 +0100 add TBQueue to the benchmark, and add a Makefile driver >--------------------------------------------------------------- bench/Makefile | 4 ++++ bench/chanbench.hs | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bench/Makefile b/bench/Makefile new file mode 100644 index 0000000..17b4884 --- /dev/null +++ b/bench/Makefile @@ -0,0 +1,4 @@ +# Run chanbench for 4 different channel types, 3 different benchmarks +all: + for i in CHAN TCHAN TQUEUE TBQUEUE; do ghc -D$$i -O2 chanbench.hs -o chanbench-$$i; done + for i in 0 1 2; do echo; echo === test $$i ===; for j in CHAN TCHAN TQUEUE TBQUEUE; do printf "%-10s" $$j; time ./chanbench-$$j $$i 2000000; done; done diff --git a/bench/chanbench.hs b/bench/chanbench.hs index 05ab909..8c534f1 100644 --- a/bench/chanbench.hs +++ b/bench/chanbench.hs @@ -6,13 +6,15 @@ import System.Environment import Control.Concurrent.Chan import Control.Concurrent.STM import Control.Concurrent.STM.TQueue +import Control.Concurrent.STM.TBQueue -- Using CPP rather than a runtime choice between channel types, -- because we want the compiler to be able to optimise the calls. -#define CHAN +-- #define CHAN -- #define TCHAN -- #define TQUEUE +-- #define TBQUEUE #ifdef CHAN newc = newChan @@ -26,6 +28,10 @@ writec c x = atomically $ writeTChan c x newc = newTQueueIO readc c = atomically $ readTQueue c writec c x = atomically $ writeTQueue c x +#elif defined(TBQUEUE) +newc = newTBQueueIO 4096 +readc c = atomically $ readTBQueue c +writec c x = atomically $ writeTBQueue c x #endif main = do @@ -47,7 +53,7 @@ runtest n test = do replicateM_ n $ writec c (1 :: Int) replicateM_ n $ readc c 2 -> do - let n10 = n `quot` 10 - replicateM_ 10 $ do - replicateM_ n10 $ writec c (1 :: Int) - replicateM_ n10 $ readc c + let n1000 = n `quot` 1000 + replicateM_ 1000 $ do + replicateM_ n1000 $ writec c (1 :: Int) + replicateM_ n1000 $ readc c _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
