github.com/mavryk-network/mvgo@v1.19.9/base58/base58bench_test.go (about)

     1  // Copyright (c) 2020-2021 Blockwatch Data Inc.
     2  // Copyright (c) 2013-2014 The btcsuite developers
     3  // Use of this source code is governed by an ISC
     4  // license that can be found in the LICENSE file.
     5  
     6  package base58_test
     7  
     8  import (
     9  	"bytes"
    10  	"fmt"
    11  	"testing"
    12  
    13  	"github.com/mavryk-network/mvgo/base58"
    14  )
    15  
    16  var (
    17  	sizes = []int{20, 32, 50, 100}
    18  )
    19  
    20  func BenchmarkEncodeBigInt(b *testing.B) {
    21  	for _, sz := range sizes {
    22  		b.Run(fmt.Sprintf("size_%d", sz), func(b *testing.B) {
    23  			data := bytes.Repeat([]byte{0xff}, sz)
    24  			b.SetBytes(int64(sz))
    25  			b.ReportAllocs()
    26  			for i := 0; i < b.N; i++ {
    27  				base58.Encode(data)
    28  			}
    29  		})
    30  	}
    31  }
    32  
    33  func BenchmarkDecodeBigInt(b *testing.B) {
    34  	for _, sz := range sizes {
    35  		b.Run(fmt.Sprintf("size_%d", sz), func(b *testing.B) {
    36  			data := bytes.Repeat([]byte{0xff}, sz)
    37  			enc := base58.Encode(data)
    38  			b.SetBytes(int64(len(enc)))
    39  			b.ReportAllocs()
    40  			for i := 0; i < b.N; i++ {
    41  				base58.Decode(enc, nil)
    42  			}
    43  		})
    44  	}
    45  }