Skip to content

Commit 7943781

Browse files
authored
Merge pull request #111 from bgamari/wip/time-units
Print times with more sensible units
2 parents d333922 + b28447c commit 7943781

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

GUI/SummaryView.hs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ setSummaryStats view SummaryStats{..} hasHeapEvents = do
186186
setTimeStats :: SummaryView -> TimeStats -> IO ()
187187
setTimeStats SummaryView{..} TimeStats{..} =
188188
mapM_ (\(label, text) -> set label [ labelText := text ])
189-
[ (labelTimeTotal , showFFloat (Just 2) (timeToSecondsDbl timeTotal) "s")
190-
, (labelTimeMutator , showFFloat (Just 2) (timeToSecondsDbl timeMutator) "s")
191-
, (labelTimeGC , showFFloat (Just 2) (timeToSecondsDbl timeGC) "s")
189+
[ (labelTimeTotal , showTimeWithUnit timeTotal)
190+
, (labelTimeMutator , showTimeWithUnit timeMutator)
191+
, (labelTimeGC , showTimeWithUnit timeGC)
192192
, (labelTimeProductivity, showFFloat (Just 1) (timeProductivity * 100) "% of mutator vs total")
193193
]
194194

@@ -563,6 +563,17 @@ sparkStats StatsAccum{dsparkTable} =
563563

564564
------------------------------------------------------------------------------
565565

566+
showTimeWithUnit :: Integral a => a -> String
567+
showTimeWithUnit t =
568+
showFFloat (Just 3) t'' unit
569+
where
570+
(t'', unit) =
571+
case timeToSecondsDbl t of
572+
t' | t' < 1e-6 -> (t' / 1e-9, "ns")
573+
| t' < 1e-3 -> (t' / 1e-6, "μs")
574+
| t' < 1 -> (t' / 1e-3, "ms")
575+
| otherwise -> (t', "s")
576+
566577
timeToSecondsDbl :: Integral a => a -> Double
567578
timeToSecondsDbl t = timeToSeconds $ fromIntegral t
568579

0 commit comments

Comments
 (0)