github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/bench/race/race_test.go (about)

     1  package race
     2  
     3  import (
     4  	"runtime"
     5  	"testing"
     6  
     7  	"golang.org/x/crypto/bcrypt"
     8  )
     9  
    10  func BenchmarkGenerateFromPassword(b *testing.B) {
    11  	for i := 0; i < b.N; i++ {
    12  		hash, _ := bcrypt.GenerateFromPassword([]byte{1, 2, 3, 4, 5}, bcrypt.DefaultCost)
    13  		runtime.KeepAlive(hash)
    14  	}
    15  }
    16  
    17  func BenchmarkCompareHashAndPassw(b *testing.B) {
    18  	hash, _ := bcrypt.GenerateFromPassword([]byte{1, 2, 3, 4, 5}, bcrypt.DefaultCost)
    19  	for i := 0; i < b.N; i++ {
    20  		err := bcrypt.CompareHashAndPassword(hash, []byte{1, 2, 3, 4, 5})
    21  		runtime.KeepAlive(err)
    22  	}
    23  }