Skip to content

Commit

Permalink
time command: add timeQuiet option
Browse files Browse the repository at this point in the history
  • Loading branch information
qsctr committed Aug 30, 2022
1 parent f5fc53d commit 0b49544
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Cryptol/REPL/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,17 +1016,20 @@ typeOfCmd str pos fnm = do
timeCmd :: String -> (Int, Int) -> Maybe FilePath -> REPL ()
timeCmd str pos fnm = do
period <- getKnownUser "timeMeasurementPeriod" :: REPL Int
rPutStrLn $ "Measuring for " ++ show period ++ " seconds"
quiet <- getKnownUser "timeQuiet"
unless quiet $
rPutStrLn $ "Measuring for " ++ show period ++ " seconds"
pExpr <- replParseExpr str pos fnm
(_, def, sig) <- replCheckExpr pExpr
replPrepareCheckedExpr def sig >>= \case
Nothing -> raise (EvalPolyError sig)
Just (_, expr) -> do
Bench.BenchmarkStats {..} <- liftModuleCmd
(rethrowEvalError . M.benchmarkExpr (fromIntegral period) expr)
rPutStrLn $ "Avg time: " ++ Bench.secs benchAvgTime
++ " Avg CPU time: " ++ Bench.secs benchAvgCpuTime
++ " Avg cycles: " ++ show benchAvgCycles
unless quiet $
rPutStrLn $ "Avg time: " ++ Bench.secs benchAvgTime
++ " Avg CPU time: " ++ Bench.secs benchAvgCpuTime
++ " Avg cycles: " ++ show benchAvgCycles
let mkStatsRec time cpuTime cycles = recordFromFields
[("avgTime", time), ("avgCpuTime", cpuTime), ("avgCycles", cycles)]
itType = E.TVRec $ mkStatsRec E.tvFloat64 E.tvFloat64 E.TVInteger
Expand Down
3 changes: 3 additions & 0 deletions src/Cryptol/REPL/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,9 @@ userOptions = mkOptionMap
, "This is a lower bound and the actual time taken might be higher if the"
, " evaluation takes a long time."
]

, simpleOpt "timeQuiet" ["time-quiet"] (EnvBool False) noCheck
"Suppress output of :time command and only bind result to `it`."
]


Expand Down

0 comments on commit 0b49544

Please sign in to comment.