github.com/nikandfor/hacked@v0.0.0-20231207014854-3b383967fdf4/hruntime/low_test.go (about)

     1  package hruntime
     2  
     3  import (
     4  	"hash/crc32"
     5  	"math/rand"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func BenchmarkCRC32(b *testing.B) {
    11  	buf := make([]byte, 1024)
    12  
    13  	for i := range buf {
    14  		buf[i] = byte(i)
    15  	}
    16  
    17  	for i := 0; i < b.N; i++ {
    18  		_ = crc32.ChecksumIEEE(buf)
    19  	}
    20  
    21  	b.SetBytes(int64(len(buf)))
    22  }
    23  
    24  func BenchmarkBytesHash(b *testing.B) {
    25  	buf := make([]byte, 1024)
    26  
    27  	for i := range buf {
    28  		buf[i] = byte(i)
    29  	}
    30  
    31  	for i := 0; i < b.N; i++ {
    32  		_ = BytesHash(buf, 0)
    33  	}
    34  
    35  	b.SetBytes(int64(len(buf)))
    36  }
    37  
    38  var rr uint32
    39  
    40  func BenchmarkRand(b *testing.B) {
    41  	r := rand.New(rand.NewSource(time.Now().UnixNano()))
    42  
    43  	for i := 0; i < b.N; i++ {
    44  		rr = r.Uint32()
    45  	}
    46  }
    47  
    48  func BenchmarkFastRand(b *testing.B) {
    49  	for i := 0; i < b.N; i++ {
    50  		rr = Fastrand()
    51  	}
    52  }