aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/xmss
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-04-12 16:14:21 -0400
committerJack Lloyd <[email protected]>2018-04-12 16:14:21 -0400
commit8b3a420571fa33ba968b36e79d751fe1db0de586 (patch)
tree000692827873b110c14e21f6770fdeb7e8f6e105 /src/lib/pubkey/xmss
parentc15d82039b916ed453202e499dcfb2dfa0abe967 (diff)
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.
Diffstat (limited to 'src/lib/pubkey/xmss')
-rw-r--r--src/lib/pubkey/xmss/xmss_tools.cpp16
1 files changed, 9 insertions, 7 deletions
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<std::thread> threads;
- threads.reserve(std::thread::hardware_concurrency());
+ threads.reserve(hardware_concurrency);
std::vector<std::chrono::nanoseconds> durations;
- std::vector<size_t> concurrency { std::thread::hardware_concurrency(),
- std::thread::hardware_concurrency() / 2 };
+ std::vector<size_t> concurrency { hardware_concurrency,
+ hardware_concurrency / 2 };
for(const auto& cc : concurrency)
{
- std::vector<XMSS_Hash> hash(std::thread::hardware_concurrency(),
+ std::vector<XMSS_Hash> hash(hardware_concurrency,
XMSS_Hash("SHA-256"));
const std::vector<uint8_t> buffer(hash[0].output_length());
std::vector<secure_vector<uint8_t>> data(
- std::thread::hardware_concurrency(),
+ hardware_concurrency,
secure_vector<uint8_t>(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++)