module BuildBox.Reports.BenchResult
(reportBenchResults)
where
import BuildBox.Pretty
import BuildBox.Aspect
import BuildBox.Benchmark.BenchResult
import Text.Printf
reportBenchResults :: Maybe Double -> [BenchResult StatsComparison] -> Doc
reportBenchResults Nothing comparisons
= vcat $ punctuate (text "\n") $ map ppr comparisons
reportBenchResults (Just swing) comparisons
= let (resultWinners, resultLosers, _)
= splitBenchResults swing comparisons
in vcat $ [ text "Total tests = " <> int (length comparisons)
, blank] ++ [reportBenchResults' swing resultWinners resultLosers]
reportBenchResults' swing resultWinners resultLosers
| [] <- resultWinners
, [] <- resultLosers
= text "ALL GOOD\n"
| otherwise
= let docWinners
| [] <- resultWinners
= []
| otherwise
= [text "-- WINNERS (had a swing of < "
<> text (printf "%+2.0f" (negate (swing * 100))) <> text "%)"
$$ (vcat $ punctuate (text "\n") $ map ppr resultWinners)
<> text "\n"]
docLosers
| [] <- resultLosers
= []
| otherwise
= [text "-- LOSERS (had a swing of > "
<> text (printf "%+2.0f" (swing * 100)) <> text "%)"
$$ (vcat $ punctuate (text "\n") $ map ppr resultLosers)
<> text "\n"]
in vcat $ docWinners ++ docLosers