summaryrefslogtreecommitdiffhomepage
path: root/Cost.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-16 16:59:25 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-16 16:59:25 -0400
commitc2eba63d11c748aeebdd3a4a3a5b015ac5e2f2c9 (patch)
treef75ee5e067fee2b36fdc75ad470fd9cc2e11268e /Cost.hs
parent9473fee1bb0f9f549de41eec9f7b7d141f2ebfd3 (diff)
downloadkeysafe-c2eba63d11c748aeebdd3a4a3a5b015ac5e2f2c9.tar.gz
add cost estimates
Diffstat (limited to 'Cost.hs')
-rw-r--r--Cost.hs34
1 files changed, 31 insertions, 3 deletions
diff --git a/Cost.hs b/Cost.hs
index 31f00a3..5aa349c 100644
--- a/Cost.hs
+++ b/Cost.hs
@@ -56,8 +56,8 @@ spotAWS = DataCenterPrice
-- which is unlikely to be the case; typically there will be many more
-- cores than GPUs. So, this underestimates the price to brute force
-- operations which run faster on GPUs.
-estimateAttack :: DataCenterPrice -> Cost BruteForceOp -> Dollars
-estimateAttack dc opcost = centsToDollars $ costcents
+estimateAttackCost :: DataCenterPrice -> Cost BruteForceOp -> Dollars
+estimateAttackCost dc opcost = centsToDollars $ costcents
where
(Seconds cpuseconds) = fst (totalCost opcost)
cpuyears = cpuseconds `div` (60*60*24*365)
@@ -70,7 +70,35 @@ newtype Cents = Cents Integer
deriving (Num, Integral, Enum, Real, Ord, Eq, Show)
newtype Dollars = Dollars Integer
- deriving (Num, Integral, Enum, Real, Ord, Eq, Show)
+ deriving (Num, Integral, Enum, Real, Ord, Eq)
+
+instance Show Dollars where
+ show (Dollars n) = go
+ [ (1000000000000, "trillion")
+ , (1000000000, "billion")
+ , (1000000, "million")
+ , (1000, "thousand")
+ ]
+ where
+ go [] = "$" ++ show n
+ go ((d, u):us)
+ | n >= d =
+ let n' = n `div` d
+ in "$" ++ show n' ++ " " ++ u
+ | otherwise = go us
centsToDollars :: Cents -> Dollars
centsToDollars (Cents c) = Dollars (c `div` 100)
+
+type Year = Integer
+
+-- | Apply Moore's law to show how a cost might vary over time.
+costOverTime :: Dollars -> Year -> [(Dollars, Year)]
+costOverTime (Dollars currcost) thisyear =
+ (Dollars currcost, thisyear) : map calc otheryears
+ where
+ otheryears = [thisyear+1, thisyear+5, thisyear+10]
+ calc y =
+ let monthdelta = (fromIntegral ((y * 12) - (thisyear * 12))) :: Double
+ cost = floor $ fromIntegral currcost / 2 ** (monthdelta / 18)
+ in (Dollars cost, y)