From 2022a5e65ca7f1331f1864236390827a7a22c707 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Tue, 7 Apr 2020 11:04:40 -0400 Subject: [PATCH] Perform one KDF benchmark at a time * Prevent using double memory when benchmarking Argon2 performance. * Improve benchmark results by not overusing CPU and memory simultaneously. Parallel benchmarks were causing artificially strained calculations resulting in a lower than desired number of rounds. --- src/crypto/kdf/Kdf.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/crypto/kdf/Kdf.cpp b/src/crypto/kdf/Kdf.cpp index b4c4427c..6a4c7fc6 100644 --- a/src/crypto/kdf/Kdf.cpp +++ b/src/crypto/kdf/Kdf.cpp @@ -71,16 +71,19 @@ void Kdf::randomizeSeed() int Kdf::benchmark(int msec) const { - BenchmarkThread thread1(msec, this); - BenchmarkThread thread2(msec, this); + // Run the benchmark twice using half the time for each run + BenchmarkThread thread(msec / 2, this); + int rounds = 0; - thread1.start(); - thread2.start(); + thread.start(); + thread.wait(); + rounds += thread.rounds(); - thread1.wait(); - thread2.wait(); + thread.start(); + thread.wait(); + rounds += thread.rounds(); - return qMax(1, (thread1.rounds() + thread2.rounds()) / 2); + return qMax(1, rounds); } Kdf::BenchmarkThread::BenchmarkThread(int msec, const Kdf* kdf)