Skip to content

Latest commit

 

History

History
195 lines (141 loc) · 6.12 KB

File metadata and controls

195 lines (141 loc) · 6.12 KB

Benchmarks

Dependencies

Example commands

make mutex num-blocks others prng-params reseed-countdown

  • The mutex benchmark compares the use of pthread_mutex_t and thread_local.
  • The others benchmark compares randp to these PRNGs:
    • RDRAND
    • RDSEED
    • getentropy
    • arc4random
  • The num-blocks, prng-params, and reseed-countdown benchmarks compare varying parameters of randp and its internal PRNG.
  • All the benchmarks take about 10 minutes.

Refine the randp parameters

Run these targets in the following order to refine the parameters of randp.

  1. make num-blocks: find optimal DEFAULT_RANDP_NUM_BLOCKS
  2. make reseed-countdown: find optimal DEFAULT_RANDP_RESEED_COUNTDOWN_MIN
  3. make prng-params: find optimal DEFAULT_AESCTR128_PRNG_NUM_KEYS, DEFAULT_AESCTR128_PRNG_NUM_ROUNDS_PER_KEY, DEFAULT_RANDP_PRNG_USE_ENC, and DEFAULT_RANDP_PRNG_USE_DAVIES_MEYER
  4. repeat

Benchmark Results

Note

The glibc arc4random is completely different that the OpenBSD arc4random.

Note

Glibc version 2.41 added support for getrandom vDSO. This dramatically sped up getentropy and arc4random on Linux. 3 4

2026-02-27

System Info

  • Linux 6.18.13-arch1-1 x86_64
  • 13th Gen Intel(R) Core(TM) i9-13980HX
  • ldd (GNU libc) 2.43
  • gcc (GCC) 15.2.1 20260209
  • libbenchmark.so.1.9.5
  • librandp.so.4.5

Fill a buffer with random bytes

Function Median time to generate 4 GiB
randp_bytes 199 ms 25.9× faster
arc4random_buf 5154 ms
getentropy 7905 ms

Get a uniform random uint32_t

Function Median time per call
randp_u32 6.33 ns 2.3× faster
arc4random 14.5 ns
rdrand32 288 ns
rdseed32 1816 ns

Note: rdrand32 and rdseed32 are wrappers for _rdrand32_step and _rdseed32_step, respectively.

Get a uniform random uint32_t less than upper_bound = [1 .. 0x100000]

Function Median time per call
randp_lt_u32 6.32 ns 3.2× more
arc4random_uniform 20.3 ns

2025-10-09

System Info

  • Linux 6.17.1-arch1-1 x86_64
  • 13th Gen Intel(R) Core(TM) i9-13980HX
  • ldd (GNU libc) 2.42
  • gcc (GCC) 15.2.1 20250813
  • libbenchmark.so.1.9.4
  • librandp.so.4.4

Fill a buffer with random bytes

Function Median time to generate 4 GiB
randp_bytes 202 ms 25.4× faster
arc4random_buf 5139 ms
getentropy 7974 ms

Get a uniform random uint32_t

Function Median time per call
randp_u32 6.65 ns 2.3× faster
arc4random 15.3 ns
rdrand32 286 ns
rdseed32 1813 ns

Note: rdrand32 and rdseed32 are wrappers for _rdrand32_step and _rdseed32_step, respectively.

Get a uniform random uint32_t less than upper_bound = [1 .. 0x100000]

Function Median calls per second
randp_lt_u32 158.683M/s 3.6× more
arc4random_uniform 43.9428M/s

2025-02-03

System Info

  • Linux 6.13.1-arch1-1 x86_64
  • 13th Gen Intel(R) Core(TM) i9-13980HX
  • ldd (GNU libc) 2.41
  • gcc (GCC) 14.2.1 20250128
  • libbenchmark.so.1.9.1
  • librandp.so.4.4

Fill a buffer with random bytes

Function Median time to generate 4 GiB
randp_bytes 189 ms 26.7× faster
arc4random_buf 5053 ms
getentropy 7782 ms

Get a uniform random uint32_t

Function Median time per call
randp_u32 6.22 ns 2.1× faster
arc4random 13.1 ns
rdrand32 287 ns
rdseed32 1809 ns

Note: rdrand32 and rdseed32 are wrappers for _rdrand32_step and _rdseed32_step, respectively.

Get a uniform random uint32_t less than upper_bound = [1 .. 0x100000]

Function Median calls per second
randp_lt_u32 153.104M/s 3.28× more
arc4random_uniform 46.6285M/s

2024-10-04

System Info

  • Linux 6.11.1-arch1-1 x86_64
  • 13th Gen Intel(R) Core(TM) i9-13950HX
  • ldd (GNU libc) 2.40
  • gcc (GCC) 14.2.1 20240910
  • libbenchmark.so.1.9.0
  • librandp.so.4.3

Fill a buffer with random bytes

Function Median time to generate 4 GiB
randp_bytes 217 ms 43× faster
getentropy 8993 ms
arc4random_buf 9410 ms

Get a uniform random uint32_t

Function Median time per call
randp_u32 6.69 ns 27× faster
arc4random 181 ns
rdrand32 304 ns
rdseed32 1825 ns

Note: rdrand32 and rdseed32 are wrappers for _rdrand32_step and _rdseed32_step, respectively.

Get a uniform random uint32_t less than upper_bound = [1 .. 0x100000]

Function Median calls per second
randp_lt_u32 149.148M/s 39× more
arc4random_uniform 3.7692M/s

Footnotes

  1. https://lists.gnu.org/archive/html/info-gnu/2022-08/msg00000.html

  2. https://lore.kernel.org/all/20220726195822.1223048-1-Jason@zx2c4.com/

  3. https://www.phoronix.com/news/glibc-getrandom-vDSO-Merged

  4. https://lwn.net/Articles/983186/