Skip to content

Commit 663fbae

Browse files
committed
FastRandom benchmark
1 parent c21cbe6 commit 663fbae

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/bench/crypto_hash.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "bench.h"
88
#include "bloom.h"
99
#include "hash.h"
10+
#include "random.h"
1011
#include "uint256.h"
1112
#include "utiltime.h"
1213
#include "crypto/ripemd160.h"
@@ -69,10 +70,34 @@ static void SipHash_32b(benchmark::State& state)
6970
}
7071
}
7172

73+
static void FastRandom_32bit(benchmark::State& state)
74+
{
75+
FastRandomContext rng(true);
76+
uint32_t x;
77+
while (state.KeepRunning()) {
78+
for (int i = 0; i < 1000000; i++) {
79+
x += rng.rand32();
80+
}
81+
}
82+
}
83+
84+
static void FastRandom_1bit(benchmark::State& state)
85+
{
86+
FastRandomContext rng(true);
87+
uint32_t x;
88+
while (state.KeepRunning()) {
89+
for (int i = 0; i < 1000000; i++) {
90+
x += rng.randbool();
91+
}
92+
}
93+
}
94+
7295
BENCHMARK(RIPEMD160);
7396
BENCHMARK(SHA1);
7497
BENCHMARK(SHA256);
7598
BENCHMARK(SHA512);
7699

77100
BENCHMARK(SHA256_32b);
78101
BENCHMARK(SipHash_32b);
102+
BENCHMARK(FastRandom_32bit);
103+
BENCHMARK(FastRandom_1bit);

0 commit comments

Comments
 (0)