perf: Avoid taking too long time with high thread counts
[tools.git] / perf / randbytes.c
index 6357bf00b6741d6dfb49a8dcbad702f2e709d217..c33618dc01d4044c221d48d82490d6f520114da6 100644 (file)
 #include <openssl/crypto.h>
 #include "perflib/perflib.h"
 
-#define NUM_CALLS_PER_BLOCK         100
-#define NUM_CALL_BLOCKS_PER_THREAD  100
-#define NUM_CALLS_PER_THREAD        (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_THREAD)
+#define NUM_CALLS_PER_BLOCK         1000
+#define NUM_CALL_BLOCKS_PER_RUN     100
+#define NUM_CALLS_PER_RUN           (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
 
 int err = 0;
 
+static int threadcount;
+
 void do_randbytes(size_t num)
 {
     int i;
     unsigned char buf[32];
 
-    for (i = 0; i < NUM_CALLS_PER_THREAD; i++)
+    for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++)
         if (!RAND_bytes(buf, sizeof(buf)))
             err = 1;
 }
 
 int main(int argc, char *argv[])
 {
-    int threadcount;
     OSSL_TIME duration;
     uint64_t us;
     double avcalltime;
@@ -70,7 +71,7 @@ int main(int argc, char *argv[])
 
     us = ossl_time2us(duration);
 
-    avcalltime = (double)us / (NUM_CALL_BLOCKS_PER_THREAD * threadcount);
+    avcalltime = (double)us / NUM_CALL_BLOCKS_PER_RUN;
 
     if (terse)
         printf("%lf\n", avcalltime);