From c2eba63d11c748aeebdd3a4a3a5b015ac5e2f2c9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 16 Aug 2016 16:59:25 -0400 Subject: add cost estimates --- Cost.hs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'Cost.hs') 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) -- cgit v1.2.3