{-# OPTIONS -fglasgow-exts #-} module Random (main) where import Bench import System.Random import Prelude hiding (take, lookup) import Data.Collections hiding (mapM_) import Data.Typeable testData :: [Int] testData = take 200000 $ randomRs (0, 2^30-1) (mkStdGen 7) testPairs = zip testData testData benchmark :: forall coll. (Typeable coll, Collection coll Int Int, Map coll Int ()) => coll -> Benchmark () benchmark typ = withType typ $ many 10 $ do let table :: coll = foldl' (flip insert) empty testData lookups [] = () lookups (x:xs) = (lookup x table :: Maybe ()) `seq` lookups xs withLab "build" $ time (table) withLab "lookup" $ time (lookups testData) withLab "delete" $ time (foldl' (flip delete) table testData) main = do mapM_ (\a -> a `seq` return ()) testData runBenchmark $ do benchmark (__::StdSet Int) benchmark (__::AvlSet Int) benchmark (__::IntSet)