|
| 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.h" |
| 6 | + |
| 7 | +#include "main.h" |
| 8 | +#include "base58.h" |
| 9 | + |
| 10 | +#include <vector> |
| 11 | +#include <string> |
| 12 | + |
| 13 | + |
| 14 | +static void Base58Encode(benchmark::State& state) |
| 15 | +{ |
| 16 | + unsigned char buff[32] = { |
| 17 | + 17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147, |
| 18 | + 227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90, |
| 19 | + 200, 24 |
| 20 | + }; |
| 21 | + unsigned char* b = buff; |
| 22 | + while (state.KeepRunning()) { |
| 23 | + EncodeBase58(b, b + 32); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | + |
| 28 | +static void Base58CheckEncode(benchmark::State& state) |
| 29 | +{ |
| 30 | + unsigned char buff[32] = { |
| 31 | + 17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147, |
| 32 | + 227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90, |
| 33 | + 200, 24 |
| 34 | + }; |
| 35 | + unsigned char* b = buff; |
| 36 | + std::vector<unsigned char> vch; |
| 37 | + vch.assign(b, b + 32); |
| 38 | + while (state.KeepRunning()) { |
| 39 | + EncodeBase58Check(vch); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +static void Base58Decode(benchmark::State& state) |
| 45 | +{ |
| 46 | + const char* addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem"; |
| 47 | + std::vector<unsigned char> vch; |
| 48 | + while (state.KeepRunning()) { |
| 49 | + DecodeBase58(addr, vch); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +BENCHMARK(Base58Encode); |
| 55 | +BENCHMARK(Base58CheckEncode); |
| 56 | +BENCHMARK(Base58Decode); |
0 commit comments