Bitcoin Core  29.1.0
P2P Digital Currency
base58.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2022 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 <base58.h>
6 #include <bench/bench.h>
7 #include <span.h>
8 
9 #include <array>
10 #include <cstring>
11 #include <vector>
12 
13 
14 static void Base58Encode(benchmark::Bench& bench)
15 {
16  static const std::array<unsigned char, 32> buff = {
17  {
18  17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
19  227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
20  200, 24
21  }
22  };
23  bench.batch(buff.size()).unit("byte").run([&] {
24  EncodeBase58(buff);
25  });
26 }
27 
28 
30 {
31  static const std::array<unsigned char, 32> buff = {
32  {
33  17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
34  227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
35  200, 24
36  }
37  };
38  bench.batch(buff.size()).unit("byte").run([&] {
39  EncodeBase58Check(buff);
40  });
41 }
42 
43 
44 static void Base58Decode(benchmark::Bench& bench)
45 {
46  const char* addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem";
47  std::vector<unsigned char> vch;
48  bench.batch(strlen(addr)).unit("byte").run([&] {
49  (void) DecodeBase58(addr, vch, 64);
50  });
51 }
52 
53 
bool DecodeBase58(const std::string &str, std::vector< unsigned char > &vchRet, int max_ret_len)
Decode a base58-encoded string (str) into a byte vector (vchRet).
Definition: base58.cpp:129
static void Base58Decode(benchmark::Bench &bench)
Definition: base58.cpp:44
static void Base58CheckEncode(benchmark::Bench &bench)
Definition: base58.cpp:29
std::string EncodeBase58(Span< const unsigned char > input)
Why base-58 instead of standard base-64 encoding?
Definition: base58.cpp:89
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
Bench & unit(char const *unit)
Sets the operation unit.
std::string EncodeBase58Check(Span< const unsigned char > input)
Encode a byte span into a base58-encoded string, including checksum.
Definition: base58.cpp:137
BENCHMARK(Base58Encode, benchmark::PriorityLevel::HIGH)
Main entry point to nanobench&#39;s benchmarking facility.
Definition: nanobench.h:627
Bench & batch(T b) noexcept
Sets the batch size.
Definition: nanobench.h:1258
static void Base58Encode(benchmark::Bench &bench)
Definition: base58.cpp:14