]> www.infradead.org Git - users/hch/fsqual.git/commitdiff
Reduce usage of std::random_device master
authorAvi Kivity <avi@scylladb.com>
Tue, 5 Jan 2021 17:15:13 +0000 (19:15 +0200)
committerAvi Kivity <avi@scylladb.com>
Tue, 5 Jan 2021 17:15:13 +0000 (19:15 +0200)
It is relatively expensive on hosts without a hardware random
number generator.

fsqual.cc

index 613178969d40eeadf17b60d2e43a12891118a05c..b8d57ae691ae8d927049ca410a4d506cc31316fb 100644 (file)
--- 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());