Bitcoin ABC  0.22.13
P2P Digital Currency
base58.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016 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 static void Base58Encode(benchmark::State &state) {
13  static const std::vector<uint8_t> buffer = {
14  17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203,
15  163, 36, 58, 147, 227, 139, 2, 215, 100, 91, 38,
16  11, 141, 253, 40, 117, 21, 16, 90, 200, 24};
17  while (state.KeepRunning()) {
18  EncodeBase58(buffer);
19  }
20 }
21 
22 static void Base58CheckEncode(benchmark::State &state) {
23  static const std::vector<uint8_t> buffer = {
24  17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203,
25  163, 36, 58, 147, 227, 139, 2, 215, 100, 91, 38,
26  11, 141, 253, 40, 117, 21, 16, 90, 200, 24};
27  while (state.KeepRunning()) {
28  EncodeBase58Check(buffer);
29  }
30 }
31 
32 static void Base58Decode(benchmark::State &state) {
33  const char *addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem";
34  std::vector<uint8_t> vch;
35  while (state.KeepRunning()) {
36  (void)DecodeBase58(addr, vch, 64);
37  }
38 }
39 
40 BENCHMARK(Base58Encode, 470 * 1000);
41 BENCHMARK(Base58CheckEncode, 320 * 1000);
42 BENCHMARK(Base58Decode, 800 * 1000);
bool KeepRunning()
Definition: bench.h:71
bool DecodeBase58(const char *psz, std::vector< uint8_t > &vch, int max_ret_len)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
Definition: base58.cpp:37
static void Base58CheckEncode(benchmark::State &state)
Definition: base58.cpp:22
std::string EncodeBase58(const uint8_t *pbegin, const uint8_t *pend)
Why base-58 instead of standard base-64 encoding?
Definition: base58.cpp:100
BENCHMARK(Base58Encode, 470 *1000)
static void Base58Encode(benchmark::State &state)
Definition: base58.cpp:12
static void Base58Decode(benchmark::State &state)
Definition: base58.cpp:32
std::string EncodeBase58Check(const std::vector< uint8_t > &vchIn)
Encode a byte vector into a base58-encoded string, including checksum.
Definition: base58.cpp:155