Created
July 25, 2014 05:39
-
-
Save chowey/24a1a23c9f6213fcc65d to your computer and use it in GitHub Desktop.
Benchmark comparison of cryptographic hashes in Go
This file contains hidden or 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
package main | |
import ( | |
"crypto/md5" | |
"crypto/rand" | |
"crypto/sha1" | |
"crypto/sha256" | |
"crypto/sha512" | |
"testing" | |
) | |
var data []byte | |
func init() { | |
// Create a big blob of random data | |
data = make([]byte, 1024*1024) | |
rand.Read(data) | |
} | |
func BenchmarkMD5(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_ = md5.Sum(data) | |
} | |
} | |
func BenchmarkSHA1(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_ = sha1.Sum(data) | |
} | |
} | |
func BenchmarkSHA224(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_ = sha256.Sum224(data) | |
} | |
} | |
func BenchmarkSHA256(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_ = sha256.Sum256(data) | |
} | |
} | |
func BenchmarkSHA384(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_ = sha512.Sum384(data) | |
} | |
} | |
func BenchmarkSHA512(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_ = sha512.Sum512(data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my Mac box: