-
-
Save jack-pappas/e0195529d7d1638b80a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Security.Cryptography | |
open System.Diagnostics | |
let bench (digest: HashAlgorithm) (input: byte[]) = | |
use digest = digest | |
let sw = Stopwatch.StartNew() | |
for _ in 1..100 do | |
digest.ComputeHash input |> ignore | |
sw.Stop() | |
printfn "%s elapsed %O" (digest.GetType().Name) sw.Elapsed | |
let input = Array.zeroCreate<byte> 10000000 | |
bench (MD5.Create()) input | |
bench (SHA1.Create()) input | |
bench (SHA256.Create()) input | |
bench (SHA512.Create()) input | |
bench (new MD5Cng()) input | |
bench (new SHA1Cng()) input | |
bench (new SHA256Cng()) input | |
bench (new SHA512Cng()) input | |
(* Output (using 64-bit F# interactive, optimizations on + .NET 4.5.2 + RyuJIT CTP5): | |
MD5CryptoServiceProvider elapsed 00:00:02.1729672 | |
SHA1CryptoServiceProvider elapsed 00:00:01.8118139 | |
SHA256Managed elapsed 00:00:08.8569736 | |
SHA512Managed elapsed 00:00:05.4977193 | |
MD5Cng elapsed 00:00:02.6360967 | |
SHA1Cng elapsed 00:00:02.3473916 | |
SHA256Cng elapsed 00:00:04.4638050 | |
SHA512Cng elapsed 00:00:03.1075717 | |
*) | |
(* Output (using 32-bit F# interactive, optimizations on + .NET 4.5.2 + RyuJIT CTP5): | |
MD5CryptoServiceProvider elapsed 00:00:01.5489103 | |
SHA1CryptoServiceProvider elapsed 00:00:01.8652378 | |
SHA256Managed elapsed 00:00:09.1432586 | |
SHA512Managed elapsed 00:00:38.1079386 | |
MD5Cng elapsed 00:00:02.6215859 | |
SHA1Cng elapsed 00:00:02.9868104 | |
SHA256Cng elapsed 00:00:07.2105084 | |
SHA512Cng elapsed 00:00:10.8999184 | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment