2016-01-12 17:01:44 +00:00
|
|
|
{- git-annex benchmark
|
|
|
|
-
|
2019-01-04 17:43:53 +00:00
|
|
|
- Copyright 2016-2019 Joey Hess <id@joeyh.name>
|
2016-01-12 17:01:44 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2016-01-12 17:01:44 +00:00
|
|
|
-}
|
|
|
|
|
2019-01-05 12:09:28 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2016-01-12 17:01:44 +00:00
|
|
|
|
|
|
|
module Command.Benchmark where
|
|
|
|
|
|
|
|
import Command
|
2019-01-04 17:43:53 +00:00
|
|
|
import Types.Benchmark
|
2016-01-12 17:01:44 +00:00
|
|
|
|
2019-01-05 12:09:28 +00:00
|
|
|
#ifdef WITH_BENCHMARK
|
2016-01-12 17:01:44 +00:00
|
|
|
import Criterion.Main
|
2019-01-04 17:43:53 +00:00
|
|
|
import Criterion.Main.Options (parseWith, Mode)
|
2019-01-05 12:09:28 +00:00
|
|
|
#endif
|
2019-01-04 17:43:53 +00:00
|
|
|
|
|
|
|
cmd :: BenchmarkGenerator -> Command
|
|
|
|
cmd generator = command "benchmark" SectionTesting
|
|
|
|
"benchmark git-annex commands"
|
|
|
|
paramNothing
|
|
|
|
(seek generator <$$> optParser)
|
|
|
|
|
2019-01-05 12:09:28 +00:00
|
|
|
#ifndef WITH_BENCHMARK
|
|
|
|
type Mode = ()
|
|
|
|
#endif
|
|
|
|
|
2019-01-04 17:43:53 +00:00
|
|
|
data BenchmarkOptions = BenchmarkOptions CmdParams Mode
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser BenchmarkOptions
|
|
|
|
optParser desc = BenchmarkOptions
|
|
|
|
<$> cmdParams desc
|
2019-01-05 12:09:28 +00:00
|
|
|
#ifdef WITH_BENCHMARK
|
2019-01-04 17:43:53 +00:00
|
|
|
-- parse criterion's options
|
|
|
|
<*> parseWith defaultConfig
|
2019-01-05 12:09:28 +00:00
|
|
|
#else
|
|
|
|
<*> pure ()
|
|
|
|
#endif
|
2019-01-04 17:43:53 +00:00
|
|
|
|
|
|
|
seek :: BenchmarkGenerator -> BenchmarkOptions -> CommandSeek
|
2019-01-05 12:09:28 +00:00
|
|
|
#ifdef WITH_BENCHMARK
|
2019-01-04 17:43:53 +00:00
|
|
|
seek generator (BenchmarkOptions ps mode) = do
|
|
|
|
runner <- generator ps
|
|
|
|
liftIO $ runMode mode [ bench (unwords ps) $ nfIO runner ]
|
2019-01-05 12:09:28 +00:00
|
|
|
#else
|
|
|
|
seek _ _ = giveup "git-annex is not built with benchmarking support"
|
|
|
|
#endif
|