Weight.hs (1269B)
1 {-# OPTIONS_GHC -fno-warn-orphans #-} 2 {-# LANGUAGE BangPatterns #-} 3 {-# LANGUAGE OverloadedStrings #-} 4 5 -- NOTE: weigh forks a subprocess per test, so each test pays ~32KB of 6 -- process initialization overhead. Direct measurement via GHC.Stats 7 -- shows actual per-call allocation is ~1.1KB for DRBG.new. 8 9 module Main where 10 11 import Control.DeepSeq 12 import qualified Crypto.DRBG.HMAC.SHA256 as DRBG256 13 import qualified Crypto.DRBG.HMAC.SHA512 as DRBG512 14 import Weigh 15 16 instance NFData (DRBG256.DRBG s) where 17 rnf d = d `seq` () 18 19 instance NFData DRBG256.Error where 20 rnf e = e `seq` () 21 22 instance NFData (DRBG512.DRBG s) where 23 rnf d = d `seq` () 24 25 main :: IO () 26 main = do 27 !drbg256 <- DRBG256.new mempty mempty mempty 28 !drbg512 <- DRBG512.new mempty mempty mempty 29 mainWith $ do 30 wgroup "HMAC-SHA256" $ do 31 io "new" (DRBG256.new mempty mempty) mempty 32 io "reseed" (DRBG256.reseed drbg256 mempty) mempty 33 io "gen (32B)" (DRBG256.gen drbg256 mempty) 32 34 io "gen (256B)" (DRBG256.gen drbg256 mempty) 256 35 wgroup "HMAC-SHA512" $ do 36 io "new" (DRBG512.new mempty mempty) mempty 37 io "reseed" (DRBG512.reseed drbg512 mempty) mempty 38 io "gen (32B)" (DRBG512.gen drbg512 mempty) 32 39 io "gen (256B)" (DRBG512.gen drbg512 mempty) 256