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