1

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

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286

1 Answers1

0

Set the timeLimit field of Config. For example:

myConfig :: Config
myConfig = defaultConfig {
              resamples = 1, timeLimit = 1
           }
András Kovács
  • 29,931
  • 3
  • 53
  • 99
  • Even if I set the timeLimit to `0.01` - it still takes a 'while' to run through all the benchmarks (which at the moment is just 3 benchmarks in total). – Chris Stryczynski Jan 13 '19 at 09:29