forked from dogecoin/dogecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bench: Benchmark GCS filter creation and matching.
Cherry-picked from: 254c85b
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2018 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <bench/bench.h> | ||
#include <blockfilter.h> | ||
|
||
static void ConstructGCSFilter(benchmark::State& state) | ||
{ | ||
GCSFilter::ElementSet elements; | ||
for (int i = 0; i < 10000; ++i) { | ||
GCSFilter::Element element(32); | ||
element[0] = static_cast<unsigned char>(i); | ||
element[1] = static_cast<unsigned char>(i >> 8); | ||
elements.insert(std::move(element)); | ||
} | ||
|
||
uint64_t siphash_k0 = 0; | ||
while (state.KeepRunning()) { | ||
GCSFilter filter(siphash_k0, 0, 20, 1 << 20, elements); | ||
|
||
siphash_k0++; | ||
} | ||
} | ||
|
||
static void MatchGCSFilter(benchmark::State& state) | ||
{ | ||
GCSFilter::ElementSet elements; | ||
for (int i = 0; i < 10000; ++i) { | ||
GCSFilter::Element element(32); | ||
element[0] = static_cast<unsigned char>(i); | ||
element[1] = static_cast<unsigned char>(i >> 8); | ||
elements.insert(std::move(element)); | ||
} | ||
GCSFilter filter(0, 0, 20, 1 << 20, elements); | ||
|
||
while (state.KeepRunning()) { | ||
filter.Match(GCSFilter::Element()); | ||
} | ||
} | ||
|
||
BENCHMARK(ConstructGCSFilter); | ||
BENCHMARK(MatchGCSFilter); |