Commits

Bryan O'Sullivan committed 90242c2

Allow a pre-benchmark prep step.

  • Participants
  • Parent commits c110d55

Comments (0)

Files changed (3)

File Criterion/Main.hs

 import Criterion.Environment (measureEnvironment)
 import Criterion.IO (note, printError)
 import Criterion.MultiMap (singleton)
-import Criterion.Monad (withConfig)
+import Criterion.Monad (Criterion, withConfig)
 import Criterion.Types (Benchmarkable(..), Benchmark(..), Pure, bench,
                         benchNames, bgroup, nf, whnf)
 import Data.List (isPrefixOf, sort)
 -- >                     ]
 -- >                    ]
 defaultMain :: [Benchmark] -> IO ()
-defaultMain = defaultMainWith defaultConfig
+defaultMain = defaultMainWith defaultConfig (return ())
 
 -- | An entry point that can be used as a @main@ function, with
 -- configurable defaults.
 -- >              cfgPlot = M.singleton KernelDensity (Window 800 600)
 -- >            }
 -- > 
--- > main = defaultMainWith myConfig [
+-- > main = defaultMainWith myConfig (return ()) [
 -- >          bench "fib 30" $ B fib 30
 -- >        ]
 --
 --
 -- Run @\"Fib --help\"@ on the command line to get a list of command
 -- line options.
-defaultMainWith :: Config -> [Benchmark] -> IO ()
-defaultMainWith defCfg bs = do
+defaultMainWith :: Config
+                -> Criterion () -- ^ Prepare data prior to executing the first benchmark.
+                -> [Benchmark]
+                -> IO ()
+defaultMainWith defCfg prep bs = do
   (cfg, args) <- parseArgs defCfg defaultOptions =<< getArgs
   withConfig cfg $
    if cfgPrintExit cfg == List
         Nothing -> return ()
       env <- measureEnvironment
       let shouldRun b = null args || any (`isPrefixOf` b) args
+      prep
       runAndAnalyse shouldRun env $ BenchGroup "" bs
 
 -- | Display an error message from a command line parsing failure, and

File examples/Judy.hs

 -- enough for us.
 myConfig = defaultConfig { cfgPerformGC = ljust True }
 
-main = defaultMainWith myConfig [
+main = defaultMainWith myConfig (return ()) [
         bgroup "judy" [
                      bench "insert 1M"   $ whnf testit 1000000
                    , bench "insert 10M"  $ whnf testit 10000000

File examples/Tiny.hs

              cfgPlot = M.singleton KernelDensity (Window 800 600)
            }
 
-main = defaultMainWith myConfig [
+main = defaultMainWith myConfig (return ()) [
          bench "fib 10" $ whnf fib 10
        , bench "fib 30" $ whnf fib 30
        , bench "intmap 50k" $ whnf intmap 50000