Commit d5ee7c85 authored by Simon Marlow's avatar Simon Marlow

add two mutable store benchmarks

parent 30a10277
......@@ -2,6 +2,7 @@ TOP = ..
include $(TOP)/mk/boilerplate.mk
SUBDIRS= circsim constraints fibheaps fulsom gc_bench happy lcss power spellcheck
mutstore1 mutstore2
# Bitrotted: ghc
# Discount treejoin: runs too quickly to see any speedup beyond a few procs
......
-- test performance of a mutable store represented as an Array of IORefs.
module Main where
import Store1
--import Store2
import Control.Monad
import System.Environment
main =
do [n] <- fmap (fmap read) getArgs
ss <- replicateM n mkStore
replicateM_ 5 (mapM_ testSequence ss)
testSequence :: Store -> IO ()
testSequence s =
do replicateM_ 5 (addElemToBucket s 3 17)
TOP = ../..
include $(TOP)/mk/boilerplate.mk
FAST_OPTS = 100000
NORM_OPTS = 300000
SLOW_OPTS = 600000
include $(TOP)/mk/target.mk
--Immutable array with IORefs to lists
module Store1 where
import Data.IORef
import Data.Array
type Store = Array Int (IORef [Int])
mkStore :: IO Store
mkStore =
do buckets <- sequence ( take 10 $ repeat (newIORef []) )
let myArray = listArray (0, 9) buckets
return $! myArray
addElemToBucket :: Store -> Int -> Int -> IO ()
addElemToBucket a k e =
do buc <- readIORef (a!k)
writeIORef (a!k) (e : buc)
-- test performance of a mutable store represented as an IOArray of lists.
module Main where
--import Store1
import Store2
import Control.Monad
import System.Environment
main =
do [n] <- fmap (fmap read) getArgs
ss <- replicateM n mkStore
replicateM_ 5 (mapM_ testSequence ss)
testSequence :: Store -> IO ()
testSequence s =
do replicateM_ 5 (addElemToBucket s 3 17)
TOP = ../..
include $(TOP)/mk/boilerplate.mk
FAST_OPTS = 100000
NORM_OPTS = 300000
SLOW_OPTS = 600000
include $(TOP)/mk/target.mk
--IOArray with lists
module Store2 where
import Data.IORef
import Data.Array.IO
type Store = IOArray Int [Int]
mkStore :: IO Store
mkStore = newArray (0, 9) []
addElemToBucket :: Store -> Int -> Int -> IO ()
addElemToBucket a k e =
do buc <- readArray a k
writeArray a k (e : buc)
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