2 * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include <openssl/rand.h>
13 #include <openssl/crypto.h>
14 #include "perflib/perflib.h"
16 #define NUM_CALLS_PER_BLOCK 100
17 #define NUM_CALL_BLOCKS_PER_THREAD 100
18 #define NUM_CALLS_PER_THREAD (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_THREAD)
22 void do_randbytes(size_t num)
25 unsigned char buf[32];
27 for (i = 0; i < NUM_CALLS_PER_THREAD; i++)
28 if (!RAND_bytes(buf, sizeof(buf)))
32 int main(int argc, char *argv[])
40 printf("Usage: randbytes threadcount\n");
44 threadcount = atoi(argv[1]);
45 if (threadcount < 1) {
46 printf("threadcount must be > 0\n");
50 if (!perflib_run_multi_thread_test(do_randbytes, threadcount, &duration)) {
51 printf("Failed to run the test\n");
56 printf("Error during test\n");
60 us = ossl_time2us(duration);
62 avcalltime = (double)us / (NUM_CALL_BLOCKS_PER_THREAD * threadcount);
64 printf("Average time per %d RAND_bytes() calls: %lfus\n",
65 NUM_CALLS_PER_BLOCK, avcalltime);