Last active
May 16, 2019 18:19
-
-
Save maruel/723039dd6a244afe71b1469838c2710c 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
package main | |
import ( | |
"crypto/sha1" | |
"crypto/sha256" | |
"crypto/sha512" | |
"fmt" | |
"hash" | |
"testing" | |
sha256simd "github.com/minio/sha256-simd" | |
"golang.org/x/crypto/blake2b" | |
"golang.org/x/crypto/sha3" | |
) | |
func inner(b *testing.B, h hash.Hash) { | |
buf := make([]byte, 256*b.N) | |
b.ResetTimer() | |
_, _ = h.Write(buf) | |
sum := h.Sum(nil) | |
b.StopTimer() | |
b.SetBytes(int64(len(buf))) | |
fmt.Sprintf("%x", sum) | |
} | |
func BenchmarkSHA1(b *testing.B) { | |
inner(b, sha1.New()) | |
} | |
func BenchmarkSHA2_256(b *testing.B) { | |
inner(b, sha256.New()) | |
} | |
func BenchmarkSHA2SIMD_256(b *testing.B) { | |
inner(b, sha256simd.New()) | |
} | |
func BenchmarkSHA2_512(b *testing.B) { | |
inner(b, sha512.New()) | |
} | |
func BenchmarkSHA3_256(b *testing.B) { | |
inner(b, sha3.New256()) | |
} | |
func BenchmarkSHA3_512(b *testing.B) { | |
inner(b, sha3.New512()) | |
} | |
func BenchmarkBlake2b_256(b *testing.B) { | |
h, _ := blake2b.New256(nil) | |
inner(b, h) | |
} | |
func BenchmarkBlake2b_512(b *testing.B) { | |
h, _ := blake2b.New512(nil) | |
inner(b, h) | |
} | |
// Fails on macPro: | |
func BenchmarkSHA2AVX512_256(b *testing.B) { | |
server := sha256simd.NewAvx512Server() | |
inner(b, sha256simd.NewAvx512(server)) | |
} |
Author
maruel
commented
May 16, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment