Commits

Bryan O'Sullivan committed 49b2b63

Make the examples build under the new regime, and add a Makefile.

  • Participants
  • Parent commits 432f5a0

Comments (0)

Files changed (3)

File examples/Fibber.hs

             return $! i * j
 
 main = defaultMain [
-        bgroup "tiny" [ bench "fib 10" $ \n -> fib (10+n-n)
-                      , bench "fib 15" $ \n -> fib (15+n-n)
-                      , bench "fib 20" $ \n -> fib (20+n-n)
-                      , bench "fib 25" $ \n -> fib (25+n-n)
+        bgroup "tiny" [ bench "fib 10" $ B fib 10
+                      , bench "fib 15" $ B fib 15
+                      , bench "fib 20" $ B fib 20
+                      , bench "fib 25" $ B fib 25
                       ],
-        bgroup "fib" [ bench "fib 10" $ \n -> fib (10+n-n)
-                     , bench "fib 35" $ \n -> fib (35+n-n)
-                     , bench "fib 37" $ \n -> fib (37+n-n)
+        bgroup "fib" [ bench "fib 10" $ B fib 10
+                     , bench "fib 35" $ B fib 35
+                     , bench "fib 37" $ B fib 37
                      ],
-        bgroup "fact" [ bench "fact 100"  $ \n -> fact (100+n-n)
-                      , bench "fact 1000" $ \n -> fact (1000+n-n)
-                      , bench "fact 3000" $ \n -> fact (3000+n-n)
+        bgroup "fact" [ bench "fact 100"  $ B fact 100
+                      , bench "fact 1000" $ B fact 1000
+                      , bench "fact 3000" $ B fact 3000
                       ],
         bgroup "fio" [ bench "fio 100"  (fio 100)
                      , bench "fio 1000" (fio 1000)

File examples/Makefile

+all := Fibber Tiny
+
+all: $(all)
+
+%: %.hs
+	ghc -O --make $<
+
+clean:
+	-rm -f *.hi *.o $(all)

File examples/Tiny.hs

+{-# LANGUAGE ScopedTypeVariables #-}
+
+import Criterion.Main
+import Control.Parallel
+import qualified Data.IntMap as I
+import Data.List (foldl')
+import Criterion.Config
+import qualified Criterion.MultiMap as M
+
+myConfig = defaultConfig {
+             -- Always display an 800x600 window.
+             cfgPlot = M.singleton KernelDensity (Window 800 600)
+           }
+
+main = defaultMainWith myConfig [
+         bench "fib 30" $ B fib 30
+       , bench "intmap 50k" $ B intmap 50000
+       , bench "intmap 75k" $ B intmap 75000
+       ]
+        
+fib :: Int -> Int
+fib 0 = 0
+fib 1 = 1
+fib n = fib (n-1) + fib (n-2)
+
+intmap :: Int -> I.IntMap Int
+intmap n = foldl' (\m k -> I.insert k 33 m) I.empty [0..n]