Chris Stryczynski
Chris Stryczynski

Reputation: 33881

How can I reduce the criterion benchmark time?

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)?

Upvotes: 1

Views: 172

Answers (1)

András Kovács
András Kovács

Reputation: 30103

Set the timeLimit field of Config. For example:

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

Upvotes: 0

Related Questions