> module Main where A tool for testing Dynamic-perfmance over (read (show x)). Compile with: $HC -cpp -DDYNAMIC -syslib concurrent -syslib lang -o DynTest DynTest.lhs or -DSTRING The DYNAMIC-version is about 8 times faster. > import Dynamic > import Concurrent > import IO The data we want to send, String-version: > data SMsg = SOne | STwo Int | SThree String | SQuit deriving (Show, Read) And now the Dynamic implementation: > data DMsg = DOne | DTwo Int | DThree String | DQuit > instance Typeable DMsg where > typeOf _ = mkAppTy msgTc [] > msgTc :: TyCon > msgTc = mkTyCon "Msg" > main = do > print "Starting benchmark:" #ifdef STRING > sbench send receive #endif #ifdef DYNAMIC > dbench dsend dreceive #endif > sbench send receive = do > ch <- newChan > sync <- newEmptyMVar > forkIO (receive sync ch 0) > send 1000 (SOne) ch > send 1000 (STwo 314) ch > send 1000 (SThree "hello world") ch > send 1 SQuit ch > takeMVar sync > dbench send receive = do > ch <- newChan > sync <- newEmptyMVar > forkIO (receive sync ch 0) > send 1000 (DOne) ch > send 1000 (DTwo 314) ch > send 1000 (DThree "hello world") ch > send 1 DQuit ch > takeMVar sync > send 0 _ _ = return () > send n m ch = do > writeChan ch (show m) > send (n-1) m ch > receive s ch n = do > m <- readChan ch > let msg = ((read m) :: SMsg) > case msg of > SQuit -> do > putMVar s () > return () > _ -> do > print ((show n)) > receive s ch (n+1) > dsend 0 _ _ = return () > dsend n m ch = do > writeChan ch (toDyn m) > dsend (n-1) m ch > dreceive s ch n = do > m <- readChan ch > let msg = fromDynamic m > case msg of > Just DQuit -> do > putMVar s () > return () > Just _ -> do > print ((show n)) > dreceive s ch (n+1)