1

我正在尝试使用标准库进行一些基准测试。

我试过一个简单的例子:

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

然而,这似乎需要几秒钟才能完成,我认为它会更快地完成?

为什么需要这么长时间?我怎样才能减少持续时间(即使以不准确为代价)?

4

1 回答 1

0

设置timeLimit字段Config。例如:

myConfig :: Config
myConfig = defaultConfig {
              resamples = 1, timeLimit = 1
           }
于 2019-01-13T08:47:05.530 回答