From 8b3a420571fa33ba968b36e79d751fe1db0de586 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 12 Apr 2018 16:14:21 -0400 Subject: In XMSS_Tools::bench_threads only call hardware_concurrency once Getting this value will typically require either a system call or a cpuid call, both of which are fairly expensive. --- src/lib/pubkey/xmss/xmss_tools.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/pubkey/xmss/xmss_tools.cpp b/src/lib/pubkey/xmss/xmss_tools.cpp index f4f762aeb..f9bd4892e 100644 --- a/src/lib/pubkey/xmss/xmss_tools.cpp +++ b/src/lib/pubkey/xmss/xmss_tools.cpp @@ -19,26 +19,28 @@ size_t XMSS_Tools::max_threads() size_t XMSS_Tools::bench_threads() { - if(std::thread::hardware_concurrency() <= 1) + const size_t hardware_concurrency = std::thread::hardware_concurrency(); + + if(hardware_concurrency <= 1) { return 1; } const size_t BENCH_ITERATIONS = 1000; std::vector threads; - threads.reserve(std::thread::hardware_concurrency()); + threads.reserve(hardware_concurrency); std::vector durations; - std::vector concurrency { std::thread::hardware_concurrency(), - std::thread::hardware_concurrency() / 2 }; + std::vector concurrency { hardware_concurrency, + hardware_concurrency / 2 }; for(const auto& cc : concurrency) { - std::vector hash(std::thread::hardware_concurrency(), + std::vector hash(hardware_concurrency, XMSS_Hash("SHA-256")); const std::vector buffer(hash[0].output_length()); std::vector> data( - std::thread::hardware_concurrency(), + hardware_concurrency, secure_vector(hash[0].output_length())); auto start = std::chrono::high_resolution_clock::now(); for(size_t i = 0; i < cc; ++i) @@ -46,7 +48,7 @@ size_t XMSS_Tools::bench_threads() auto& hs = hash[i]; auto& d = data[i]; - const size_t n_iters = BENCH_ITERATIONS * (std::thread::hardware_concurrency() / cc); + const size_t n_iters = BENCH_ITERATIONS * (hardware_concurrency / cc); threads.emplace_back(std::thread([n_iters, &hs, &d]() { for(size_t n = 0; n < n_iters; n++) -- cgit v1.2.3