Add --sort-by-name flag

To sort the benchmarks by name instead of sorting them by field value or
percent diff.
This commit is contained in:
Harendra Kumar 2021-06-07 18:05:33 +05:30 committed by Harendra Kumar
parent edbb7b8010
commit 5537b0bfc2
2 changed files with 26 additions and 8 deletions

View File

@ -25,18 +25,24 @@ data BenchType
data Options = Options
{ genGraphs :: Bool
, sortByName :: Bool
, benchType :: Maybe BenchType
, fields :: [String]
} deriving Show
defaultOptions :: Options
defaultOptions = Options False Nothing ["time"]
defaultOptions = Options False False Nothing ["time"]
setGenGraphs :: Monad m => Bool -> StateT (a, Options) m ()
setGenGraphs val = do
(args, opts) <- get
put (args, opts { genGraphs = val })
setSortByName :: Monad m => Bool -> StateT (a, Options) m ()
setSortByName val = do
(args, opts) <- get
put (args, opts { sortByName = val })
setBenchType :: Monad m => BenchType -> StateT (a, Options) m ()
setBenchType val = do
(args, opts) <- get
@ -88,6 +94,7 @@ parseOptions = do
parseOpt opt =
case opt of
"--graphs" -> setGenGraphs True
"--sort-by-name" -> setSortByName True
"--benchmark" -> parseBench
"--fields" -> parseFields
str -> do
@ -140,16 +147,21 @@ showComparisons Options{..} cfg inp out =
------------------------------------------------------------------------------
selectBench
:: (SortColumn -> Maybe GroupStyle -> Either String [(String, Double)])
:: Bool
-> (SortColumn -> Maybe GroupStyle -> Either String [(String, Double)])
-> [String]
selectBench f =
selectBench sortName f =
reverse
$ fmap fst
$ either
(const $ either error (sortOn snd) $ f (ColumnIndex 0) (Just PercentDiff))
(sortOn snd)
(const $ either error sortFunc $ f (ColumnIndex 0) (Just PercentDiff))
sortFunc
$ f (ColumnIndex 1) (Just PercentDiff)
where
sortFunc = if sortName then sortOn fst else sortOn snd
benchShow ::
Options
-> Config
@ -172,7 +184,7 @@ main = do
Just opts@Options{fields = fs, benchType = btype} ->
let cfg = defaultConfig
{ presentation = Groups PercentDiff
, selectBenchmarks = selectBench
, selectBenchmarks = selectBench (sortByName opts)
, selectFields = filter
( flip elem fs
. fmap toLower

View File

@ -12,6 +12,7 @@ print_help () {
echo " [--benchmarks <"bench1 bench2 ..." | help>]"
echo " [--prefix <benchmark name prefix to match>"
echo " [--fields <"field1 field2 ..." | help>]"
echo " [--sort-by-name]"
echo " [--graphs]"
echo " [--no-measure]"
echo " [--append]"
@ -290,8 +291,11 @@ run_reports() {
for i in $1
do
echo "Generating reports for ${i}..."
$prog $(test "$GRAPH" = 1 && echo "--graphs") \
--benchmark $i --fields "$FIELDS"
$prog \
--benchmark $i \
$(test "$GRAPH" = 1 && echo "--graphs") \
$(test "$SORT_BY_NAME" = 1 && echo "--sort-by-name") \
--fields "$FIELDS"
done
}
@ -316,6 +320,7 @@ CANDIDATE=
APPEND=0
LONG=0
RAW=0
SORT_BY_NAME=0
GRAPH=0
MEASURE=1
@ -350,6 +355,7 @@ do
--raw) RAW=1; shift ;;
--append) APPEND=1; shift ;;
--long) LONG=1; shift ;;
--sort-by-name) SORT_BY_NAME=1; shift ;;
--graphs) GRAPH=1; shift ;;
--no-measure) MEASURE=0; shift ;;
--dev-build) RUNNING_DEVBUILD=1; shift ;;