Add bench-fibo example as proper benchmark

Also move sources to src/ so there are no accidental rebuilding.
This commit is contained in:
Oleg Grenrus 2022-01-15 12:01:22 +02:00 committed by ˌbodʲɪˈɡrʲim
parent 1fb79b5d0a
commit 3790437ae4
4 changed files with 25 additions and 2 deletions

View File

@ -65,4 +65,4 @@ jobs:
apt-get install -y ghc libghc-tasty-dev
run: |
ghc --version
ghc Test/Tasty/Bench.hs
ghc src/Test/Tasty/Bench.hs

15
bench/bench-fibo.hs Normal file
View File

@ -0,0 +1,15 @@
module Main (main) where
import Test.Tasty.Bench
fibo :: Int -> Integer
fibo n = if n < 2 then toInteger n else fibo (n - 1) + fibo (n - 2)
main :: IO ()
main = defaultMain
[ bgroup "fibonacci numbers"
[ bench "fifth" $ nf fibo 5
, bench "tenth" $ nf fibo 10
, bench "twentieth" $ nf fibo 20
]
]

View File

@ -45,7 +45,7 @@ flag debug
library
exposed-modules: Test.Tasty.Bench
hs-source-dirs: .
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -O2 -Wall -fno-warn-unused-imports
if impl(ghc < 7.10)
@ -66,3 +66,11 @@ library
if flag(debug)
cpp-options: -DDEBUG
benchmark bench-fibo
default-language: Haskell2010
hs-source-dirs: bench
main-is: bench-fibo.hs
type: exitcode-stdio-1.0
build-depends: base, tasty-bench
ghc-options: "-with-rtsopts=-A32m"