github.com/fluhus/gostuff@v0.4.1-0.20240331134726-be71864f2b5d/rhash/bench_test.go (about)

     1  package rhash
     2  
     3  import (
     4  	"crypto/rand"
     5  	"testing"
     6  )
     7  
     8  func BenchmarkWrite1K(b *testing.B) {
     9  	const n = 20
    10  	buf := make([]byte, 1024)
    11  	rand.Read(buf)
    12  	b.Run("buz32", func(b *testing.B) {
    13  		h := NewBuz32(n)
    14  		for i := 0; i < b.N; i++ {
    15  			h.Write(buf)
    16  		}
    17  	})
    18  	b.Run("buz64", func(b *testing.B) {
    19  		h := NewBuz64(n)
    20  		for i := 0; i < b.N; i++ {
    21  			h.Write(buf)
    22  		}
    23  	})
    24  	b.Run("rabin32", func(b *testing.B) {
    25  		h := NewRabinFingerprint32(n)
    26  		for i := 0; i < b.N; i++ {
    27  			h.Write(buf)
    28  		}
    29  	})
    30  	b.Run("rabin64", func(b *testing.B) {
    31  		h := NewRabinFingerprint64(n)
    32  		for i := 0; i < b.N; i++ {
    33  			h.Write(buf)
    34  		}
    35  	})
    36  }