16enum class Difference {
22constexpr size_t NUM_PAIRS{4'096};
24std::vector<std::pair<uint256, uint256>> MakePairs(Difference difference)
27 std::vector<std::pair<uint256, uint256>> pairs;
28 pairs.reserve(NUM_PAIRS);
30 for (
size_t i{0}; i < NUM_PAIRS; ++i) {
34 const size_t position{difference == Difference::FIRST_BYTE ? 0 :
uint256::size() - 1};
35 lhs.begin()[position] = i % 2 == 0 ? 0 : 255;
36 rhs.begin()[position] = i % 2 == 0 ? 255 : 0;
38 pairs.emplace_back(lhs, rhs);
43template <
typename Comparator>
44void Comparison(
benchmark::Bench& bench, Difference difference, Comparator comparator)
46 const auto pairs{MakePairs(difference)};
48 for (
const auto& [lhs, rhs] : pairs) {
61 Comparison(bench, Difference::FIRST_BYTE, [](
const uint256& lhs,
const uint256& rhs) {
return lhs == rhs; });
66 Comparison(bench, Difference::LAST_BYTE, [](
const uint256& lhs,
const uint256& rhs) {
return lhs == rhs; });
76 Comparison(bench, Difference::FIRST_BYTE, [](
const uint256& lhs,
const uint256& rhs) {
return lhs < rhs; });
81 Comparison(bench, Difference::LAST_BYTE, [](
const uint256& lhs,
const uint256& rhs) {
return lhs < rhs; });
uint256 rand256() noexcept
generate a random uint256.
Main entry point to nanobench's benchmarking facility.
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Bench & batch(T b) noexcept
Sets the batch size.
Bench & unit(char const *unit)
Sets the operation unit.
static constexpr unsigned int size()
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
BENCHMARK(Uint256EqualIdentical)