Bitcoin Core  0.19.99
P2P Digital Currency
base58.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <bench/bench.h>
6 
7 #include <base58.h>
8 
9 #include <array>
10 #include <vector>
11 
12 
13 static void Base58Encode(benchmark::State& state)
14 {
15  static const std::array<unsigned char, 32> buff = {
16  {
17  17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
18  227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
19  200, 24
20  }
21  };
22  while (state.KeepRunning()) {
23  EncodeBase58(buff.data(), buff.data() + buff.size());
24  }
25 }
26 
27 
29 {
30  static const std::array<unsigned char, 32> buff = {
31  {
32  17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
33  227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
34  200, 24
35  }
36  };
37  std::vector<unsigned char> vch;
38  vch.assign(buff.begin(), buff.end());
39  while (state.KeepRunning()) {
40  EncodeBase58Check(vch);
41  }
42 }
43 
44 
45 static void Base58Decode(benchmark::State& state)
46 {
47  const char* addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem";
48  std::vector<unsigned char> vch;
49  while (state.KeepRunning()) {
50  (void) DecodeBase58(addr, vch, 64);
51  }
52 }
53 
54 
55 BENCHMARK(Base58Encode, 470 * 1000);
56 BENCHMARK(Base58CheckEncode, 320 * 1000);
57 BENCHMARK(Base58Decode, 800 * 1000);
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Why base-58 instead of standard base-64 encoding?
Definition: base58.cpp:87
bool KeepRunning()
Definition: bench.h:72
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch, int max_ret_len)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
Definition: base58.cpp:38
static void Base58CheckEncode(benchmark::State &state)
Definition: base58.cpp:28
BENCHMARK(Base58Encode, 470 *1000)
static void Base58Encode(benchmark::State &state)
Definition: base58.cpp:13
std::string EncodeBase58Check(const std::vector< unsigned char > &vchIn)
Encode a byte vector into a base58-encoded string, including checksum.
Definition: base58.cpp:140
static void Base58Decode(benchmark::State &state)
Definition: base58.cpp:45