Last active
July 20, 2017 21:13
-
-
Save redbo/24b3e10d72979b08a34a95b2768f8058 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
/* | |
BenchmarkMd5-4 3000000 521 ns/op | |
BenchmarkMinioBlake-4 2000000 692 ns/op | |
BenchmarkRegularBlake-4 2000000 838 ns/op | |
BenchmarkRegularBlakeSum-4 3000000 522 ns/op | |
BenchmarkSha3_256-4 1000000 1336 ns/op | |
BenchmarkSha3_Shake128-4 1000000 1213 ns/op | |
*/ | |
package main | |
import ( | |
"crypto/md5" | |
"encoding/hex" | |
"testing" | |
"golang.org/x/crypto/sha3" | |
minioBlake "github.com/minio/blake2b-simd" | |
regularBlake "golang.org/x/crypto/blake2b" | |
) | |
func BenchmarkMd5(b *testing.B) { | |
h := md5.New() | |
for i := 0; i < b.N; i++ { | |
h.Reset() | |
h.Write([]byte("hello")) | |
if hex.EncodeToString(h.Sum(nil)) == "" { | |
panic("NOT RIGHT") | |
} | |
} | |
} | |
func BenchmarkMinioBlake(b *testing.B) { | |
h := minioBlake.New256() | |
for i := 0; i < b.N; i++ { | |
h.Reset() | |
h.Write([]byte("hello")) | |
if hex.EncodeToString(h.Sum(nil)) == "" { | |
panic("NOT RIGHT") | |
} | |
} | |
} | |
func BenchmarkRegularBlake(b *testing.B) { | |
h, err := regularBlake.New256([]byte("KEY")) | |
if err != nil { | |
panic("ERROR AND STUFF") | |
} | |
for i := 0; i < b.N; i++ { | |
h.Reset() | |
h.Write([]byte("hello")) | |
if hex.EncodeToString(h.Sum(nil)) == "" { | |
panic("NOT RIGHT") | |
} | |
} | |
} | |
func BenchmarkRegularBlakeSum(b *testing.B) { | |
blake := func(b []byte) string { | |
x := regularBlake.Sum256(b) | |
return hex.EncodeToString(x[:]) | |
} | |
for i := 0; i < b.N; i++ { | |
if blake([]byte("hello")) == "" { | |
panic("NOT RIGHT") | |
} | |
} | |
} | |
func BenchmarkSha3_256(b *testing.B) { | |
h := sha3.New256() | |
for i := 0; i < b.N; i++ { | |
h.Reset() | |
h.Write([]byte("hello")) | |
if hex.EncodeToString(h.Sum(nil)) == "" { | |
panic("NOT RIGHT") | |
} | |
} | |
} | |
func BenchmarkSha3_Shake128(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
scratch := make([]byte, 16) | |
sha3.ShakeSum128(scratch, []byte("hello")) | |
if hex.EncodeToString(scratch) != "8eb4b6a932f280335ee1a279f8c208a3" { | |
panic("NOT RIGHT") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment