Commits

Bryan O'Sullivan  committed 7c155e1

Un-bit-rot the examples

  • Participants
  • Parent commits af621e5

Comments (0)

Files changed (5)

-^(?:\.cabal-sandbox|cabal\.sandbox\.config|dist)$
+^(?:examples/)?(?:\.cabal-sandbox|cabal\.sandbox\.config|dist)$
 \.(?:aux|eventlog|h[ip]|log|[oa]|orig|prof|png|ps|swp)$
 ~$
 syntax: glob

File criterion.cabal

 cabal-version:  >= 1.8
 extra-source-files:
   README.markdown
+  examples/*.cabal
   examples/*.hs
   examples/*.html
   js-src/excanvas_r3.zip

File examples/Fibber.hs

 
 import Criterion.Main
 
-fib :: Int -> Int
-fib n | n < 0     = error "negative!"
-      | otherwise = go (fromIntegral n)
+fib :: Int -> Integer
+fib m | m < 0     = error "negative!"
+      | otherwise = go (fromIntegral m :: Integer)
   where
     go 0 = 0
     go 1 = 1
             j <- go (i-1)
             return $! i * j
 
+main :: IO ()
 main = defaultMain [
         bgroup "tiny" [ bench "fib 10" $ whnf fib 10
                       , bench "fib 15" $ whnf fib 15
                       , bench "fact 1000" $ whnf fact 1000
                       , bench "fact 3000" $ whnf fact 3000
                       ],
-        bgroup "fio" [ bench "fio 100"  (fio 100)
-                     , bench "fio 1000" (fio 1000)
-                     , bench "fio 3000" (fio 3000)
+        bgroup "fio" [ bench "fio 100"  $ whnfIO (fio 100)
+                     , bench "fio 1000" $ whnfIO (fio 1000)
+                     , bench "fio 3000" $ whnfIO (fio 3000)
                      ]
        ]

File examples/Makefile

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

File examples/criterion-examples.cabal

+name:          criterion-examples
+version:       0
+synopsis:      Examples for the criterion benchmarking system
+description:   Examples for the criterion benchmarking system
+homepage:      https://github.com/bos/criterion
+license:       BSD3
+license-file:  ../LICENSE
+author:        Bryan O'Sullivan <bos@serpentine.com>
+maintainer:    Bryan O'Sullivan <bos@serpentine.com>
+category:      Benchmarks
+build-type:    Simple
+cabal-version: >=1.8
+
+executable fibber
+  main-is: Fibber.hs
+
+  ghc-options: -Wall -rtsopts
+  build-depends:
+    base == 4.*,
+    criterion