Changeset View
Changeset View
Standalone View
Standalone View
src/bench/crypto_hash.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | while (state.KeepRunning()) { | ||||
for (int i = 0; i < 1000000; i++) { | for (int i = 0; i < 1000000; i++) { | ||||
*((uint64_t *)x.begin()) = SipHashUint256(0, i, x); | *((uint64_t *)x.begin()) = SipHashUint256(0, i, x); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static void FastRandom_32bit(benchmark::State &state) { | static void FastRandom_32bit(benchmark::State &state) { | ||||
FastRandomContext rng(true); | FastRandomContext rng(true); | ||||
uint32_t x; | uint32_t x = 0; | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
for (int i = 0; i < 1000000; i++) { | for (int i = 0; i < 1000000; i++) { | ||||
x += rng.rand32(); | x += rng.rand32(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static void FastRandom_1bit(benchmark::State &state) { | static void FastRandom_1bit(benchmark::State &state) { | ||||
FastRandomContext rng(true); | FastRandomContext rng(true); | ||||
uint32_t x; | uint32_t x = 0; | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
for (int i = 0; i < 1000000; i++) { | for (int i = 0; i < 1000000; i++) { | ||||
x += rng.randbool(); | x += rng.randbool(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
BENCHMARK(RIPEMD160); | BENCHMARK(RIPEMD160); | ||||
BENCHMARK(SHA1); | BENCHMARK(SHA1); | ||||
BENCHMARK(SHA256); | BENCHMARK(SHA256); | ||||
BENCHMARK(SHA512); | BENCHMARK(SHA512); | ||||
BENCHMARK(SHA256_32b); | BENCHMARK(SHA256_32b); | ||||
BENCHMARK(SipHash_32b); | BENCHMARK(SipHash_32b); | ||||
BENCHMARK(FastRandom_32bit); | BENCHMARK(FastRandom_32bit); | ||||
BENCHMARK(FastRandom_1bit); | BENCHMARK(FastRandom_1bit); |