Reputation: 12138
The following code named fib.hs
import Criterion.Main (defaultMain)
fibZ = 1:1:zipWith (+) fibZ (tail fibZ)
main = defaultMain [
bench "fibZ 10" $ \n -> fibZ (10+n-n)
]
errors with
fib.hs:45:10: Not in scope: `bench'
What is wrong? I have borrowed this example from here.
Upvotes: 1
Views: 659
Reputation: 15038
Use
import Criterion.Main
instead of
import Criterion.Main (defaultMain)
The function bench
from Criterion.Main
is not in scope because you're importing only defaultMain
. Using bgroup
is not necessary.
Here's a full working example:
import Criterion.Main
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
main = defaultMain [
bench "fib 10" $ nf fib 10
, bench "fib 30" $ nf fib 30
, bench "fib 35" $ nf fib 35
]
If you're wondering what these nf
thingies are for, look at this section of the documentation.
Upvotes: 8
Reputation: 36143
The library has changed since that blog post was written. Now you should write:
import Criterion.Main
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
main = defaultMain [
bgroup "fib" [ bench "fib 10" $ B fib 10
, bench "fib 35" $ B fib 35
, bench "fib 37" $ B fib 37
]
]
This was taken directly from the "Running benchmarks" section of the Hackage documentation for Criterion.Main.
Upvotes: 3