From: Avi Kivity Date: Tue, 5 Jan 2021 17:15:13 +0000 (+0200) Subject: Reduce usage of std::random_device X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=e2e8897bfd6d9f0b63c9e3fb9270e3aca61e9908;p=users%2Fhch%2Ffsqual.git Reduce usage of std::random_device It is relatively expensive on hosts without a hardware random number generator. --- diff --git a/fsqual.cc b/fsqual.cc index 6131789..b8d57ae 100644 --- a/fsqual.cc +++ b/fsqual.cc @@ -79,7 +79,8 @@ void run_test(unsigned iodepth, size_t bufsize, bool pretruncate, bool prezero, fdatasync(fd); free(buf); } - std::random_device random_device; + static thread_local std::random_device s_random_device; + std::default_random_engine random_engine(s_random_device()); while (completed < nr) { auto i = unsigned(0); while (initiated < nr && current_depth < iodepth) { @@ -90,7 +91,7 @@ void run_test(unsigned iodepth, size_t bufsize, bool pretruncate, bool prezero, } ++current_depth; } - std::shuffle(iocbs.begin(), iocbs.begin() + i, random_device); + std::shuffle(iocbs.begin(), iocbs.begin() + i, random_engine); if (i) { with_ctxsw_counting(ctxsw, [&] { io_submit(ioctx, i, iocbps.data());