How can I reduce the criterion benchmark time?

163 Views Asked by At

I'm trying to use the criterion library to do some benchmarking.

I've tried a simple example:

module Main where

import Criterion.Types
import Criterion.Main

myConfig :: Config
myConfig = defaultConfig {
              resamples = 1
           }

main :: IO ()
main = do
  let f = (\x -> bench (show x)  $ whnf xyz x)
  defaultMainWith myConfig [
    bgroup "fib" [ 
                  env (pure 5) f
                ]
    ]

xyz :: Int -> [Double]
xyz 0 = []
xyz x = case x of
  100 -> [sin $ fromIntegral x] ++ (xyz (x - 1))
  _ -> [sin $ fromIntegral (2 * x)] ++ (xyz (x - 1))

However this seems to take a few seconds to complete, I'd assume it'd complete significantly quicker?

Why is it taking so long? How can I reduce the duration (even at the cost of inaccuracy)?

1

There are 1 best solutions below

1
András Kovács On

Set the timeLimit field of Config. For example:

myConfig :: Config
myConfig = defaultConfig {
              resamples = 1, timeLimit = 1
           }