Created
December 29, 2022 11:35
-
-
Save klauspost/01d8428905d17c2ad1f66b16f1bd1e2f 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_test | |
import ( | |
"crypto/sha1" | |
"math/rand" | |
"testing" | |
"github.com/zeebo/xxh3" | |
) | |
func BenchmarkHash8K(b *testing.B) { | |
var block [8192]byte | |
r := rand.New(rand.NewSource(1)) | |
r.Read(block[:]) | |
b.Run("sha-1", func(b *testing.B) { | |
h := sha1.New() | |
sum := make([]byte, h.Size()) | |
b.SetBytes(int64(len(block))) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
h.Reset() | |
h.Write(block[:]) | |
h.Sum(sum[:0]) | |
} | |
}) | |
b.Run("xxh3", func(b *testing.B) { | |
b.SetBytes(int64(len(block))) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
xxh3.Hash(block[:]) | |
} | |
}) | |
b.Run("xxh3-seed", func(b *testing.B) { | |
b.SetBytes(int64(len(block))) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
xxh3.HashSeed(block[:], uint64(i)) | |
} | |
}) | |
b.Run("xxh128", func(b *testing.B) { | |
b.SetBytes(int64(len(block))) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
xxh3.Hash128(block[:]) | |
} | |
}) | |
b.Run("xxh128-seed", func(b *testing.B) { | |
b.SetBytes(int64(len(block))) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
xxh3.Hash128Seed(block[:], uint64(i)) | |
} | |
}) | |
} |
Author
klauspost
commented
Dec 29, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment