|
| 1 | +// Copyright (c) 2019 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 <iostream> |
| 6 | + |
| 7 | +#include <bench/bench.h> |
| 8 | +#include <crypto/poly1305.h> |
| 9 | + |
| 10 | +/* Number of bytes to process per iteration */ |
| 11 | +static constexpr uint64_t BUFFER_SIZE_TINY = 64; |
| 12 | +static constexpr uint64_t BUFFER_SIZE_SMALL = 256; |
| 13 | +static constexpr uint64_t BUFFER_SIZE_LARGE = 1024*1024; |
| 14 | + |
| 15 | +static void POLY1305(benchmark::State& state, size_t buffersize) |
| 16 | +{ |
| 17 | + std::vector<unsigned char> tag(POLY1305_TAGLEN, 0); |
| 18 | + std::vector<unsigned char> key(POLY1305_KEYLEN, 0); |
| 19 | + std::vector<unsigned char> in(buffersize, 0); |
| 20 | + while (state.KeepRunning()) |
| 21 | + poly1305_auth(tag.data(), in.data(), in.size(), key.data()); |
| 22 | +} |
| 23 | + |
| 24 | +static void POLY1305_64BYTES(benchmark::State& state) |
| 25 | +{ |
| 26 | + POLY1305(state, BUFFER_SIZE_TINY); |
| 27 | +} |
| 28 | + |
| 29 | +static void POLY1305_256BYTES(benchmark::State& state) |
| 30 | +{ |
| 31 | + POLY1305(state, BUFFER_SIZE_SMALL); |
| 32 | +} |
| 33 | + |
| 34 | +static void POLY1305_1MB(benchmark::State& state) |
| 35 | +{ |
| 36 | + POLY1305(state, BUFFER_SIZE_LARGE); |
| 37 | +} |
| 38 | + |
| 39 | +BENCHMARK(POLY1305_64BYTES, 500000); |
| 40 | +BENCHMARK(POLY1305_256BYTES, 250000); |
| 41 | +BENCHMARK(POLY1305_1MB, 340); |
0 commit comments