Main.hs (931B)
1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Main where 4 5 import Criterion.Main 6 import qualified Crypto.Hash.SHA256 as SHA256 7 import qualified Data.ByteString as BS 8 import qualified Data.ByteString.Lazy as BL 9 import qualified Data.Digest.Pure.SHA as SHA 10 11 main :: IO () 12 main = defaultMain [ 13 suite 14 ] 15 16 suite :: Benchmark 17 suite = env setup $ \ ~(bs, bl) -> 18 bgroup "ppad-sha256" [ 19 bgroup "SHA256 (32B input)" [ 20 bench "hash" $ whnf SHA256.hash bs 21 , bench "hash_lazy" $ whnf SHA256.hash_lazy bl 22 , bench "SHA.sha256" $ whnf SHA.sha256 bl 23 ] 24 , bgroup "HMAC-SHA256 (32B input)" [ 25 bench "hmac" $ whnf (SHA256.hmac "key") bs 26 , bench "hmac_lazy" $ whnf (SHA256.hmac_lazy "key") bl 27 , bench "SHA.hmacSha256" $ whnf (SHA.hmacSha256 "key") bl 28 ] 29 ] 30 where 31 setup = do 32 let bs_32B = BS.replicate 32 0 33 bl_32B = BL.fromStrict bs_32B 34 pure (bs_32B, bl_32B) 35