github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/crypto/keys/armor/armor_bench_test.go (about)

     1  package armor
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/gnolang/gno/tm2/pkg/crypto"
    10  	"github.com/gnolang/gno/tm2/pkg/crypto/bcrypt"
    11  )
    12  
    13  func BenchmarkBcryptGenerateFromPassword(b *testing.B) {
    14  	if testing.Short() {
    15  		b.Skip("skipping testing in short mode")
    16  	}
    17  
    18  	passphrase := []byte("passphrase")
    19  	for securityParam := 9; securityParam < 16; securityParam++ {
    20  		param := securityParam
    21  		b.Run(fmt.Sprintf("benchmark-security-param-%d", param), func(b *testing.B) {
    22  			saltBytes := crypto.CRandBytes(16)
    23  			b.ResetTimer()
    24  			for i := 0; i < b.N; i++ {
    25  				_, err := bcrypt.GenerateFromPassword(saltBytes, passphrase, param)
    26  				require.Nil(b, err)
    27  			}
    28  		})
    29  	}
    30  }