diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2019-05-22 21:05:50 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2019-05-22 21:06:00 +0200 |
commit | fdc951ad040a9117bc79f12086ce874b4c2aa55a (patch) | |
tree | 24c06058bab340b3d4ea4b1be7e44628d687ec77 | |
parent | 1c177c3a004f91eca743bb3a0dd9534a544026d5 (diff) | |
parent | df9e15f092c18a8047f09307576c2b77b9c8d01c (diff) |
Merge #16073: refactor: Improve CRollingBloomFilter::reset by using std::fill
df9e15f092c18a8047f09307576c2b77b9c8d01c refactor: Improve CRollingBloomFilter::reset by using std::fill (João Barbosa)
d2dbc7da26e1ca40200521c05a0b1ca75578acd2 bench: Add benchmark for CRollingBloomFilter::reset (João Barbosa)
Pull request description:
Cleaner code. Also improves performance with `--enable-debug` (which is meaningless to non-developers).
Before:
```
# Benchmark, evals, iterations, total, min, max, median
RollingBloomReset, 5, 150, 19.3008, 0.0254917, 0.0259195, 0.0257395
```
After:
```
# Benchmark, evals, iterations, total, min, max, median
RollingBloomReset, 5, 150, 5.43269, 0.00720651, 0.00729697, 0.00724854
```
ACKs for commit df9e15:
MarcoFalke:
re-utACK df9e15f092
jamesob:
re-utACK https://github.com/bitcoin/bitcoin/pull/16073/commits/df9e15f092c18a8047f09307576c2b77b9c8d01c
Tree-SHA512: 22038411dfd41afad77b17a3da9ee04476ffbd4d215dcf47bdd9f14588759bc328a55d958dcebc2036b52ce4c56f79b1284eae11e56ddfaf21f0b2ee1c6a914a
-rw-r--r-- | src/bench/rollingbloom.cpp | 9 | ||||
-rw-r--r-- | src/bloom.cpp | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/bench/rollingbloom.cpp b/src/bench/rollingbloom.cpp index 0a99ea3184..4016530dac 100644 --- a/src/bench/rollingbloom.cpp +++ b/src/bench/rollingbloom.cpp @@ -28,4 +28,13 @@ static void RollingBloom(benchmark::State& state) } } +static void RollingBloomReset(benchmark::State& state) +{ + CRollingBloomFilter filter(120000, 0.000001); + while (state.KeepRunning()) { + filter.reset(); + } +} + BENCHMARK(RollingBloom, 1500 * 1000); +BENCHMARK(RollingBloomReset, 20000); diff --git a/src/bloom.cpp b/src/bloom.cpp index 7732cee275..a061925089 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -14,6 +14,7 @@ #include <math.h> #include <stdlib.h> +#include <algorithm> #define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455 #define LN2 0.6931471805599453094172321214581765680755001343602552 @@ -304,7 +305,5 @@ void CRollingBloomFilter::reset() nTweak = GetRand(std::numeric_limits<unsigned int>::max()); nEntriesThisGeneration = 0; nGeneration = 1; - for (std::vector<uint64_t>::iterator it = data.begin(); it != data.end(); it++) { - *it = 0; - } + std::fill(data.begin(), data.end(), 0); } |