on master help sign in
Add --sort-by-name flag

To sort the benchmarks by name instead of sorting them by field value or percent diff.

commit5537b0bfc2df62f4553f3580415d55739c4d0ab4 authorHarendra Kumar <harendra@composewell.com> dateMon 7 Jun 2021, 18:05 (5 years ago) parentedbb7b8
2 files changed+26−8
benchmark/Chart.hs+18−6 bin/bench.sh+8−2
benchmark/Chart.hs+18−6
@@ -25,18 +25,24 @@ data BenchType
2525
2626data Options = Options
2727 { genGraphs :: Bool
28+ , sortByName :: Bool
2829 , benchType :: Maybe BenchType
2930 , fields :: [String]
3031 } deriving Show
3132
3233defaultOptions :: Options
33−defaultOptions = Options False Nothing ["time"]
34+defaultOptions = Options False False Nothing ["time"]
3435
3536setGenGraphs :: Monad m => Bool -> StateT (a, Options) m ()
3637setGenGraphs val = do
3738 (args, opts) <- get
3839 put (args, opts { genGraphs = val })
3940
41+setSortByName :: Monad m => Bool -> StateT (a, Options) m ()
42+setSortByName val = do
43+ (args, opts) <- get
44+ put (args, opts { sortByName = val })
45+
4046setBenchType :: Monad m => BenchType -> StateT (a, Options) m ()
4147setBenchType val = do
4248 (args, opts) <- get
@@ -88,6 +94,7 @@ parseOptions = do
8894 parseOpt opt =
8995 case opt of
9096 "--graphs" -> setGenGraphs True
97+ "--sort-by-name" -> setSortByName True
9198 "--benchmark" -> parseBench
9299 "--fields" -> parseFields
93100 str -> do
@@ -140,16 +147,21 @@ showComparisons Options{..} cfg inp out =
140147------------------------------------------------------------------------------
141148
142149selectBench
143− :: (SortColumn -> Maybe GroupStyle -> Either String [(String, Double)])
150+ :: Bool
151+ -> (SortColumn -> Maybe GroupStyle -> Either String [(String, Double)])
144152 -> [String]
145−selectBench f =
153+selectBench sortName f =
146154 reverse
147155 $ fmap fst
148156 $ either
149− (const $ either error (sortOn snd) $ f (ColumnIndex 0) (Just PercentDiff))
150− (sortOn snd)
157+ (const $ either error sortFunc $ f (ColumnIndex 0) (Just PercentDiff))
158+ sortFunc
151159 $ f (ColumnIndex 1) (Just PercentDiff)
152160
161+ where
162+
163+ sortFunc = if sortName then sortOn fst else sortOn snd
164+
153165benchShow ::
154166 Options
155167 -> Config
@@ -172,7 +184,7 @@ main = do
172184 Just opts@Options{fields = fs, benchType = btype} ->
173185 let cfg = defaultConfig
174186 { presentation = Groups PercentDiff
175− , selectBenchmarks = selectBench
187+ , selectBenchmarks = selectBench (sortByName opts)
176188 , selectFields = filter
177189 ( flip elem fs
178190 . fmap toLower
bin/bench.sh+8−2
@@ -12,6 +12,7 @@ print_help () {
1212 echo " [--benchmarks <"bench1 bench2 ..." | help>]"
1313 echo " [--prefix <benchmark name prefix to match>"
1414 echo " [--fields <"field1 field2 ..." | help>]"
15+ echo " [--sort-by-name]"
1516 echo " [--graphs]"
1617 echo " [--no-measure]"
1718 echo " [--append]"
@@ -290,8 +291,11 @@ run_reports() {
290291 for i in $1
291292 do
292293 echo "Generating reports for ${i}..."
293− $prog $(test "$GRAPH" = 1 && echo "--graphs") \
294− --benchmark $i --fields "$FIELDS"
294+ $prog \
295+ --benchmark $i \
296+ $(test "$GRAPH" = 1 && echo "--graphs") \
297+ $(test "$SORT_BY_NAME" = 1 && echo "--sort-by-name") \
298+ --fields "$FIELDS"
295299 done
296300}
297301
@@ -316,6 +320,7 @@ CANDIDATE=
316320APPEND=0
317321LONG=0
318322RAW=0
323+SORT_BY_NAME=0
319324GRAPH=0
320325MEASURE=1
321326
@@ -350,6 +355,7 @@ do
350355 --raw) RAW=1; shift ;;
351356 --append) APPEND=1; shift ;;
352357 --long) LONG=1; shift ;;
358+ --sort-by-name) SORT_BY_NAME=1; shift ;;
353359 --graphs) GRAPH=1; shift ;;
354360 --no-measure) MEASURE=0; shift ;;
355361 --dev-build) RUNNING_DEVBUILD=1; shift ;;