github.com/MetalBlockchain/metalgo@v1.11.9/utils/crypto/secp256k1/secp256k1_benchmark_test.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package secp256k1
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/MetalBlockchain/metalgo/utils"
    12  	"github.com/MetalBlockchain/metalgo/utils/hashing"
    13  )
    14  
    15  func BenchmarkVerify(b *testing.B) {
    16  	require := require.New(b)
    17  
    18  	privateKey, err := NewPrivateKey()
    19  	require.NoError(err)
    20  
    21  	message := utils.RandomBytes(512)
    22  	hash := hashing.ComputeHash256(message)
    23  
    24  	publicKey := privateKey.PublicKey()
    25  	signature, err := privateKey.SignHash(hash)
    26  	require.NoError(err)
    27  
    28  	b.ResetTimer()
    29  
    30  	for n := 0; n < b.N; n++ {
    31  		require.True(publicKey.VerifyHash(hash, signature))
    32  	}
    33  }