简体   繁体   English

在 Haskell 中使用标准

[英]Using Criterion in Haskell

I am very new to Haskell.我对 Haskell 很陌生。

I am trying to use Criterion to get performance data.我正在尝试使用 Criterion 来获取性能数据。 My Main module is as follows:我的主要模块如下:

module Main where
import SingleThreadedBlockChain
import Data.Time.Clock.System (getSystemTime)
import System.IO (readFile)
import System.TimeIt
import System.Environment ( getArgs )
import Criterion.Main

main :: IO ()
main = do
    args <- getArgs
    time <- getSystemTime
    content <- readFile (args !! 0)
    defaultMain [
      bench "putStrLn" $ nfIO (putStrLn ("The last block is " ++ show (last (makeBlockChain "" (lines content) 0 (show time)))))
     ]

I am trying to use the Criterion documentation + things I've seen on StackOverflow to get this working.我正在尝试使用 Criterion 文档 + 我在 StackOverflow 上看到的东西来完成这项工作。 I'm getting the following error:我收到以下错误:

Error: none of the specified names matches a benchmark

I thought I would be benchmarking IO.我以为我会对 IO 进行基准测试。 From the examples I've seen, the names don't always match the benchmarks.从我看到的示例中,名称并不总是与基准匹配。 Could someone explain how the names should relate to the benchmarks?有人可以解释这些名称应该如何与基准相关吗?

Criterion's defaultMain does its own cli argument parsing. Criterion 的defaultMain进行自己的 cli 参数解析。 It uses the first argument to try and match a specific benchmark name to run (in your case you only have "putStrLn" ).它使用第一个参数来尝试匹配要运行的特定基准名称(在您的情况下,您只有"putStrLn" )。 If you want to do your own argument parsing you can change the arguments before passing to defaultMain like this:如果您想做自己的参数解析,您可以在传递给 defaultMain 之前更改defaultMain ,如下所示:

args <- getArgs
withArgs (drop 1 args) $ defaultMain ...

This will hide the first argument from defaultMain so you can use it as you please.这将隐藏defaultMain中的第一个参数,以便您可以随意使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM