Skip to content

Commit fdc951a

Browse files
committed
Merge #16073: refactor: Improve CRollingBloomFilter::reset by using std::fill
df9e15f refactor: Improve CRollingBloomFilter::reset by using std::fill (João Barbosa) d2dbc7d 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 df9e15f jamesob: re-utACK bitcoin/bitcoin@df9e15f Tree-SHA512: 22038411dfd41afad77b17a3da9ee04476ffbd4d215dcf47bdd9f14588759bc328a55d958dcebc2036b52ce4c56f79b1284eae11e56ddfaf21f0b2ee1c6a914a
2 parents 1c177c3 + df9e15f commit fdc951a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/bench/rollingbloom.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,13 @@ static void RollingBloom(benchmark::State& state)
2828
}
2929
}
3030

31+
static void RollingBloomReset(benchmark::State& state)
32+
{
33+
CRollingBloomFilter filter(120000, 0.000001);
34+
while (state.KeepRunning()) {
35+
filter.reset();
36+
}
37+
}
38+
3139
BENCHMARK(RollingBloom, 1500 * 1000);
40+
BENCHMARK(RollingBloomReset, 20000);

src/bloom.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <math.h>
1515
#include <stdlib.h>
1616

17+
#include <algorithm>
1718

1819
#define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
1920
#define LN2 0.6931471805599453094172321214581765680755001343602552
@@ -304,7 +305,5 @@ void CRollingBloomFilter::reset()
304305
nTweak = GetRand(std::numeric_limits<unsigned int>::max());
305306
nEntriesThisGeneration = 0;
306307
nGeneration = 1;
307-
for (std::vector<uint64_t>::iterator it = data.begin(); it != data.end(); it++) {
308-
*it = 0;
309-
}
308+
std::fill(data.begin(), data.end(), 0);
310309
}

0 commit comments

Comments
 (0)