-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1420 from GaloisInc/time-command
Add `:time` command
- Loading branch information
Showing
13 changed files
with
197 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- | Simple benchmarking of IO functions. | ||
module Cryptol.Utils.Benchmark | ||
( BenchmarkStats (..) | ||
, benchmark | ||
, secs | ||
) where | ||
|
||
import Criterion.Measurement (runBenchmark, secs, threshold) | ||
import Criterion.Measurement.Types | ||
import Data.Int | ||
import qualified Data.Vector as V | ||
import qualified Data.Vector.Unboxed as U | ||
|
||
-- | Statistics returned by 'benchmark'. | ||
-- | ||
-- This is extremely crude compared to the full analysis that criterion can do, | ||
-- but is enough for now. | ||
data BenchmarkStats = BenchmarkStats | ||
{ benchAvgTime :: !Double | ||
, benchAvgCpuTime :: !Double | ||
, benchAvgCycles :: !Int64 | ||
} deriving Show | ||
|
||
-- | Benchmark the application of the given function to the given input and the | ||
-- execution of the resulting IO action to WHNF, spending at least the given | ||
-- amount of time in seconds to collect measurements. | ||
benchmark :: Double -> (a -> IO b) -> a -> IO BenchmarkStats | ||
benchmark period f x = do | ||
(meas, _) <- runBenchmark (whnfAppIO f x) period | ||
let meas' = rescale <$> V.filter ((>= threshold) . measTime) meas | ||
len = length meas' | ||
sumMeasure sel = U.sum $ measure sel meas' | ||
pure BenchmarkStats | ||
{ benchAvgTime = sumMeasure measTime / fromIntegral len | ||
, benchAvgCpuTime = sumMeasure measCpuTime / fromIntegral len | ||
, benchAvgCycles = sumMeasure measCycles `div` fromIntegral len } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- | Useful information about various types. | ||
module Cryptol.Utils.Types where | ||
|
||
-- | Exponent and precision of 32-bit IEEE-754 floating point. | ||
float32ExpPrec :: (Integer, Integer) | ||
float32ExpPrec = (8, 24) | ||
|
||
-- | Exponent and precision of 64-bit IEEE-754 floating point. | ||
float64ExpPrec :: (Integer, Integer) | ||
float64ExpPrec = (11, 53) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:set timeQuiet=on | ||
:time 0x1 + 0x2 | ||
:t it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Loading module Cryptol | ||
it : {avgTime : Float 11 53, avgCpuTime : Float 11 53, avgCycles : Integer} |