我正在尝试使用标准库来做一些基准测试。
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))
然而,这似乎需要几秒钟来完成,我想它会完成显着更快?
为什么要花这么长时间?如何缩短持续时间(即使以不准确为代价)?