Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line options picked up by criterion library

I have used the libraries criterion and cmdargs.

When I compile the program completely without cmdargs and run it e.g. ./prog --help then I get some unwanted response from criterion about the possible options and the number of runs etc..

When I compile and run it as below the command line options are first picked up by my code then then read by criterion. Criterion then subsequently reports and error telling me that the option --byte is unknown. I have not seen anything in the criterion documentation how this could be switched off or worked around. Is there a way to clear out the command line options ofter I have read them? Otherwise I would need to use e.g. CPUTime instead of criterion, that is OK to me since I do to really require the loads of extra functionality and data that criterion delivers.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}

import System.Console.CmdArgs

data Strlen = Strlen {byte :: Int} deriving (Data, Typeable, Show)

strlen = cmdArgsMode $ Strlen {byte = def} &= summary "MessagePack benchmark v0.04"

main = do
  n <- cmdArgsRun strlen
  let datastring = take (byte n) $ randomRs ('a','z') (mkStdGen 3)
  putStrLn "Starting..."
  conn <- connect "192.168.35.62" 8081
  defaultMain [bench "sendReceive" $ whnfIO (mywl conn datastring)] 
like image 630
J Fritsch Avatar asked Dec 08 '11 17:12

J Fritsch


2 Answers

Use System.Environment.withArgs. Parse the command line arguments first with cmdArgs, then pass what you haven't used to criterion:

main = do
    (flags, remaining) <- parseArgsHowever
    act according to flags
    withArgs remaining $
        defaultMain [ ... ]
like image 192
Daniel Fischer Avatar answered Oct 18 '22 15:10

Daniel Fischer


Take a look at the criterion source. You should be able to write your own defaultMainWith function that handles args however you want, including ignoring them, or ignoring unknown args, or etc...

like image 20
sclv Avatar answered Oct 18 '22 17:10

sclv