Bitcoin ABC  0.24.10
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::Bench &bench) {
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  bench.batch(buffer.size()).unit("byte").run([&] { EncodeBase58(buffer); });
18 }
19 
20 static void Base58CheckEncode(benchmark::Bench &bench) {
21  static const std::vector<uint8_t> buffer = {
22  17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203,
23  163, 36, 58, 147, 227, 139, 2, 215, 100, 91, 38,
24  11, 141, 253, 40, 117, 21, 16, 90, 200, 24};
25  bench.batch(buffer.size()).unit("byte").run([&] {
26  EncodeBase58Check(buffer);
27  });
28 }
29 
30 static void Base58Decode(benchmark::Bench &bench) {
31  const char *addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem";
32  std::vector<uint8_t> vch;
33  bench.batch(strlen(addr)).unit("byte").run([&] {
34  (void)DecodeBase58(addr, vch, 64);
35  });
36 }
37 
ankerl::nanobench::Bench::batch
ANKERL_NANOBENCH(NODISCARD) std Bench & batch(T b) noexcept
Sets the batch size.
BENCHMARK
BENCHMARK(Base58Encode)
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
EncodeBase58Check
std::string EncodeBase58Check(Span< const uint8_t > input)
Encode a byte span into a base58-encoded string, including checksum.
Definition: base58.cpp:151
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
bench.h
Base58Decode
static void Base58Decode(benchmark::Bench &bench)
Definition: base58.cpp:30
Base58Encode
static void Base58Encode(benchmark::Bench &bench)
Definition: base58.cpp:12
base58.h
Base58CheckEncode
static void Base58CheckEncode(benchmark::Bench &bench)
Definition: base58.cpp:20
DecodeBase58
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
EncodeBase58
std::string EncodeBase58(Span< const uint8_t > input)
Why base-58 instead of standard base-64 encoding?
Definition: base58.cpp:100