github.com/turingchain2020/turingchain@v1.1.21/wallet/bipwallet/basen/bench_test.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package basen_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/turingchain2020/turingchain/wallet/bipwallet/basen"
    11  )
    12  
    13  // These benchmarks mirror the ones in encoding/base64, and results
    14  // should be comparable to those.
    15  
    16  func BenchmarkBase58EncodeToString(b *testing.B) {
    17  	data := make([]byte, 8192)
    18  	data[0] = 0xff // without this, it's just skipping zero bytes
    19  	b.SetBytes(int64(len(data)))
    20  	for i := 0; i < b.N; i++ {
    21  		x := basen.Base58.EncodeToString(data)
    22  		_ = x
    23  	}
    24  }
    25  
    26  func BenchmarkBase58DecodeString(b *testing.B) {
    27  	data := make([]byte, 8192)
    28  	data[0] = 0xff // without this, it's just skipping zero bytes
    29  	s := basen.Base58.EncodeToString(data)
    30  	b.SetBytes(int64(len(s)))
    31  	for i := 0; i < b.N; i++ {
    32  		x, err := basen.Base58.DecodeString(s)
    33  		if err != nil {
    34  			b.Fatal(err)
    35  		}
    36  		_ = x
    37  	}
    38  }
    39  
    40  func BenchmarkBase62EncodeToString(b *testing.B) {
    41  	data := make([]byte, 8192)
    42  	data[0] = 0xff // without this, it's just skipping zero bytes
    43  	b.SetBytes(int64(len(data)))
    44  	for i := 0; i < b.N; i++ {
    45  		x := basen.Base62.EncodeToString(data)
    46  		_ = x
    47  	}
    48  }
    49  
    50  func BenchmarkBase62DecodeString(b *testing.B) {
    51  	data := make([]byte, 8192)
    52  	data[0] = 0xff // without this, it's just skipping zero bytes
    53  	s := basen.Base62.EncodeToString(data)
    54  	b.SetBytes(int64(len(s)))
    55  	for i := 0; i < b.N; i++ {
    56  		x, err := basen.Base62.DecodeString(s)
    57  		if err != nil {
    58  			b.Fatal(err)
    59  		}
    60  		_ = x
    61  	}
    62  }