Bitcoin ABC  0.22.13
P2P Digital Currency
cashaddr.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Bitcoin 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 #include <cashaddr.h>
7 
8 #include <string>
9 #include <vector>
10 
11 static void CashAddrEncode(benchmark::State &state) {
12  std::vector<uint8_t> buffer = {17, 79, 8, 99, 150, 189, 208, 162,
13  22, 23, 203, 163, 36, 58, 147, 227,
14  139, 2, 215, 100, 91, 38, 11, 141,
15  253, 40, 117, 21, 16, 90, 200, 24};
16  while (state.KeepRunning()) {
17  cashaddr::Encode("bitcoincash", buffer);
18  }
19 }
20 
21 static void CashAddrDecode(benchmark::State &state) {
22  const char *addrWithPrefix =
23  "bitcoincash:qprnwmr02d7ky9m693qufj5mgkpf4wvssv0w86tkjd";
24  const char *addrNoPrefix = "qprnwmr02d7ky9m693qufj5mgkpf4wvssv0w86tkjd";
25  while (state.KeepRunning()) {
26  cashaddr::Decode(addrWithPrefix, "bitcoincash");
27  cashaddr::Decode(addrNoPrefix, "bitcoincash");
28  }
29 }
30 
31 BENCHMARK(CashAddrEncode, 800 * 1000);
32 BENCHMARK(CashAddrDecode, 800 * 1000);
bool KeepRunning()
Definition: bench.h:71
static void CashAddrDecode(benchmark::State &state)
Definition: cashaddr.cpp:21
static void CashAddrEncode(benchmark::State &state)
Definition: cashaddr.cpp:11
std::pair< std::string, data > Decode(const std::string &str, const std::string &default_prefix)
Decode a cashaddr string.
Definition: cashaddr.cpp:214
BENCHMARK(CashAddrEncode, 800 *1000)
std::string Encode(const std::string &prefix, const data &payload)
Encode a cashaddr string.
Definition: cashaddr.cpp:198