Main.hs (931B)
1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Main where 4 5 import Criterion.Main 6 import qualified Crypto.Hash.SHA512 as SHA512 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-sha512" [ 19 bgroup "SHA512 (32B input)" [ 20 bench "hash" $ whnf SHA512.hash bs 21 , bench "hash_lazy" $ whnf SHA512.hash_lazy bl 22 , bench "SHA.sha512" $ whnf SHA.sha512 bl 23 ] 24 , bgroup "HMAC-SHA512 (32B input)" [ 25 bench "hmac" $ whnf (SHA512.hmac "key") bs 26 , bench "hmac_lazy" $ whnf (SHA512.hmac_lazy "key") bl 27 , bench "SHA.hmacSha512" $ whnf (SHA.hmacSha512 "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