diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-08-30 14:42:06 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-08-30 14:42:06 -0400 |
commit | c273ac0173c9b277b2ba08a086e3091ba32d4319 (patch) | |
tree | 3cb1d60625b537f38e6194c1c80a8b119a9b0aaf /Types | |
parent | fe975ad122c77b4936f3e28c868b056fdaf2f842 (diff) | |
download | keysafe-c273ac0173c9b277b2ba08a086e3091ba32d4319.tar.gz |
Improve time estimates, taking into account the number of cores.
This only affects time estimates while keysafe is generating hashes;
it does not affect cost estimates to brute-force.
Diffstat (limited to 'Types')
-rw-r--r-- | Types/Cost.hs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Types/Cost.hs b/Types/Cost.hs index 0e017bb..372c43d 100644 --- a/Types/Cost.hs +++ b/Types/Cost.hs @@ -9,22 +9,26 @@ module Types.Cost where -- | An estimated cost to perform an operation. data Cost op - = CPUCost Seconds -- ^ using 1 physical CPU core + = CPUCost Seconds Divisibility + -- ^ cost in Seconds, using 1 physical CPU core deriving (Show, Eq, Ord) -unknownCost :: Cost op -unknownCost = CPUCost (Seconds 0) - newtype Seconds = Seconds Integer deriving (Num, Eq, Ord, Show) +-- | How many CPU cores a single run of an operation can be divided amoung. +newtype Divisibility = Divisibility Integer + deriving (Show, Eq, Ord) + data UsingHardware = UsingCPU | UsingGPU | UsingASIC deriving (Show) instance Monoid (Cost t) where - mempty = CPUCost (Seconds 0) - CPUCost (Seconds a) `mappend` CPUCost (Seconds b) = - CPUCost (Seconds (a+b)) + mempty = CPUCost (Seconds 0) (Divisibility 1) + CPUCost (Seconds a) (Divisibility x) `mappend` CPUCost (Seconds b) (Divisibility y) = + -- Take maximum divisibility, to avoid over-estimating + -- the total cost. + CPUCost (Seconds (a+b)) (Divisibility $ max x y) -- | Operations whose cost can be measured. data DecryptionOp |