Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add simple benchmarks

  • Loading branch information...
commit 20378b5c26a8d445bd6d35d96f60b2a291e8f7af 1 parent fbd031a
@vincenthz authored
Showing with 68 additions and 0 deletions.
  1. +42 −0 Bench.hs
  2. +26 −0 cryptohash.cabal
View
42 Bench.hs
@@ -0,0 +1,42 @@
+import Criterion.Main
+import qualified Data.ByteString as B
+import qualified Crypto.Hash.MD2 as MD2
+import qualified Crypto.Hash.MD4 as MD4
+import qualified Crypto.Hash.MD5 as MD5
+import qualified Crypto.Hash.SHA1 as SHA1
+import qualified Crypto.Hash.SHA224 as SHA224
+import qualified Crypto.Hash.SHA256 as SHA256
+import qualified Crypto.Hash.SHA384 as SHA384
+import qualified Crypto.Hash.SHA512 as SHA512
+import qualified Crypto.Hash.SHA512t as SHA512t
+import qualified Crypto.Hash.RIPEMD160 as RIPEMD160
+import qualified Crypto.Hash.Tiger as Tiger
+import qualified Crypto.Hash.Skein256 as Skein256
+import qualified Crypto.Hash.Skein512 as Skein512
+
+allHashs =
+ [ ("MD2",MD2.hash)
+ , ("MD4",MD4.hash)
+ , ("MD5",MD5.hash)
+ , ("SHA1",SHA1.hash)
+ , ("SHA224",SHA224.hash)
+ , ("SHA256",SHA256.hash)
+ , ("SHA384",SHA384.hash)
+ , ("SHA512",SHA512.hash)
+ , ("SHA512t-512",(SHA512t.hash 512))
+ , ("RIPEMD160",RIPEMD160.hash)
+ , ("Tiger",Tiger.hash)
+ , ("Skein256-256",Skein256.hash 256)
+ , ("Skein512-512",Skein512.hash 512)
+ ]
+
+benchHash :: Int -> (B.ByteString -> B.ByteString) -> Pure
+benchHash sz f = whnf f (B.replicate sz 0)
+
+withHashes f = map f allHashs
+
+main = defaultMain
+ [ bgroup "hash-256b" (withHashes (\(name, f) -> bench name $ benchHash 256 f))
+ , bgroup "hash-4Kb" (withHashes (\(name, f) -> bench name $ benchHash 4096 f))
+ , bgroup "hash-1Mb" (withHashes (\(name, f) -> bench name $ benchHash (1*1024*1024) f))
+ ]
View
26 cryptohash.cabal
@@ -28,6 +28,10 @@ Flag test
Description: Build unit test
Default: False
+Flag benchmark
+ Description: Build benchmark test
+ Default: False
+
Flag cryptoapi
Description: Defines crypto-api instances
Default: True
@@ -87,6 +91,28 @@ Executable Tests
Build-depends: crypto-api >= 0.5, tagged >= 0.1, cereal >= 0.2
cpp-options: -DHAVE_CRYPTOAPI
+Executable Bench
+ Main-Is: Bench.hs
+ Extensions: ForeignFunctionInterface
+ C-sources: cbits/sha1.c
+ cbits/sha256.c
+ cbits/sha512.c
+ cbits/md2.c
+ cbits/md4.c
+ cbits/md5.c
+ cbits/ripemd.c
+ cbits/skein256.c
+ cbits/skein512.c
+ cbits/tiger.c
+ if flag(benchmark)
+ Buildable: True
+ Build-depends: base >= 4, bytestring, criterion
+ else
+ Buildable: False
+ if flag(cryptoapi)
+ Build-depends: crypto-api >= 0.5, tagged >= 0.1, cereal >= 0.2
+ cpp-options: -DHAVE_CRYPTOAPI
+
source-repository head
type: git
location: git://github.com/vincenthz/hs-cryptohash
Please sign in to comment.
Something went wrong with that request. Please try again.