module Hyperion.PrintReport (printReports) where
import Numeric
import Control.Lens (view)
import Data.Text (unpack)
import Data.HashMap.Strict (HashMap)
import Hyperion.Internal
import Hyperion.Report
import Text.PrettyPrint.ANSI.Leijen
formatReport :: Report -> Doc
formatReport report =
green (bold (text (unpack (view reportBenchName report)))) <> line
<> (indent 2 $ text ("Bench time: " ++ prettyNanos (view reportTimeInNanos report)))
<> line
where
show2decs x= showFFloat (Just 2) x ""
prettyNanos :: Double -> String
prettyNanos x
| x > 1e9 = show2decs (x/1e9) ++ "s"
| x > 1e6 = show2decs (x/1e6) ++ "ms"
| x > 1e3 = show2decs (x/1e3) ++ "us"
| otherwise = show2decs x ++ "ns"
printReports :: HashMap BenchmarkId Report -> IO ()
printReports report = do
putDoc $ foldMap formatReport report