summaryrefslogtreecommitdiffhomepage
path: root/Cost.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Cost.hs')
-rw-r--r--Cost.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/Cost.hs b/Cost.hs
index 77c2c4c..dc2438e 100644
--- a/Cost.hs
+++ b/Cost.hs
@@ -22,7 +22,7 @@ totalCost (CPUCost s _) = (s, [UsingCPU])
raiseCostPower :: Cost c -> Entropy e -> Cost c
raiseCostPower c (Entropy e) = mapCost (* 2^e) c
-mapCost :: (Integer -> Integer) -> Cost op -> Cost op
+mapCost :: (Rational-> Rational) -> Cost op -> Cost op
mapCost f (CPUCost (Seconds n) d) = CPUCost (Seconds (f n)) d
type NumCores = Integer
@@ -30,14 +30,15 @@ type NumCores = Integer
showCostMinutes :: NumCores -> Cost op -> String
showCostMinutes numcores (CPUCost (Seconds n) (Divisibility d))
| n' < 61 = "1 minute"
- | otherwise = show (n' `div` 60) ++ " minutes"
+ | otherwise = show (n' / 60) ++ " minutes"
where
- n' = n `div` min numcores d
+ n' :: Double
+ n' = fromRational n / fromIntegral (min numcores d)
-- If an operation took n seconds on a number of cores,
-- multiply to get the CPUCost, which is for a single core.
coreCost :: NumCores -> Seconds -> Divisibility -> Cost op
-coreCost cores (Seconds n) d = CPUCost (Seconds (cores * n)) d
+coreCost cores (Seconds n) d = CPUCost (Seconds (fromIntegral cores * n)) d
castCost :: Cost a -> Cost b
castCost (CPUCost s d) = CPUCost s d
@@ -82,11 +83,11 @@ estimateAttackCost :: DataCenterPrice -> Cost BruteForceOp -> Dollars
estimateAttackCost dc opcost = centsToDollars $ costcents
where
(Seconds cpuseconds) = fst (totalCost opcost)
- cpuyears = cpuseconds `div` (60*60*24*365)
+ cpuyears = cpuseconds / (60*60*24*365)
costpercpuyear = Cents $
fromIntegral (instanceCostPerHour dc) * 24 * 365
`div` (instanceCpuCores dc * instanceCpuCoreMultiplier dc)
- costcents = Cents cpuyears * costpercpuyear
+ costcents = Cents (ceiling cpuyears) * costpercpuyear
newtype Cents = Cents Integer
deriving (Num, Integral, Enum, Real, Ord, Eq, Show)