2

I am very new to Haskell.

I am trying to use Criterion to get performance data. 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. I'm getting the following error:

Error: none of the specified names matches a benchmark

I thought I would be benchmarking 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?

1 Answer 1

3

Criterion's defaultMain does its own cli argument parsing. It uses the first argument to try and match a specific benchmark name to run (in your case you only have "putStrLn"). If you want to do your own argument parsing you can change the arguments before passing to defaultMain like this:

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

This will hide the first argument from defaultMain so you can use it as you please.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.