commit 7895e4004f7c2823fb3be3d1242fbfe54a078e37
parent 7658d532fc4da747f9d8aad2b4b896d688f0de5a
Author: Jared Tobin <jared@jtobin.io>
Date: Wed, 11 Sep 2024 16:44:53 +0400
bench: add basic benchmark suite
Diffstat:
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/bench/Main.hs b/bench/Main.hs
@@ -0,0 +1,32 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import Criterion.Main
+import qualified Crypto.Hash.SHA256 as SHA256
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy as BL
+
+main :: IO ()
+main = defaultMain [
+ suite
+ ]
+
+suite :: Benchmark
+suite = env setup $ \ ~(bs, bl) ->
+ bgroup "ppad-sha256" [
+ bgroup "SHA256 (32B input)" [
+ bench "hash" $ whnf SHA256.hash bs
+ , bench "hash_lazy" $ whnf SHA256.hash_lazy bl
+ ]
+ , bgroup "HMAC-SHA256 (32B input)" [
+ bench "hmac" $ whnf (SHA256.hmac "key") bs
+ , bench "hmac_lazy" $ whnf (SHA256.hmac_lazy "key") bl
+ ]
+ ]
+ where
+ setup = do
+ let bs_32B = BS.replicate 32 0
+ bl_32B = BL.fromStrict bs_32B
+ pure (bs_32B, bl_32B)
+
diff --git a/ppad-sha256.cabal b/ppad-sha256.cabal
@@ -46,3 +46,17 @@ test-suite sha256-tests
, tasty
, tasty-hunit
+benchmark sha256-bench
+ type: exitcode-stdio-1.0
+ default-language: Haskell2010
+ hs-source-dirs: bench
+ main-is: Main.hs
+
+ ghc-options:
+ -rtsopts -O2 -Wall -fno-warn-orphans
+
+ build-depends:
+ base
+ , bytestring
+ , criterion
+ , ppad-sha256