S. Dale
S. Dale

Reputation: 46

Using Criterion in Haskell

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?

Upvotes: 2

Views: 451

Answers (1)

soupi
soupi

Reputation: 1013

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.

Upvotes: 3

Related Questions