amazon-corretto-crypto-provider
amazon-corretto-crypto-provider copied to clipboard
Improve SecureRandom benchmarks (especially in multi-threaded settings)
Issue #, if available: N/A
Description of changes:
- Rename Drbg.java benchmark to Random.java and add more benchmarks (SUN/NativePrng, java.util.random, and some baseline using copy instead of randomness generation). SUN/NativePrng is the default Java implementation of SecureRandom when ACCP is not installed.
- Remove configuration line in build.gradle.kts forcing single thread in all benchmarks. This is because command line arguments override annotations, and we need to use multiple threads in some benchmarks.
- Use average measurement (ns/op) in build.gradle.kts instead of throughput (op/ns). This is because for multi-threaded benchmark of randomness generation, we want to know the duration of a single randomness generation on a single thread (and we want to check if performance drops because of multi-threading).
- Make the data variable (the target of randomness generation) thread-local to avoid L1 cache contention.
- Add a few more benchmarks: a. multiThreadedLocal where the SecureRandom instance is thread local, instead of global: this is useful for users of ACCP to know whether they should have SecureRandom be thread local or not. b. singleThreadedNew creating a new instance of SecureRandom: this is useful for users of ACCP to know whether it is ok to instantiate a SecureRandom every time they need it, or to instead create a global instance. c. A variant of the benchmarks generating 4 bytes of random data, instead of 1,024 bytes. For example, generating a random int requires 4 bytes of random data.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
I've rebased to split the commits in two:
- rename
Drbg.javaintoRandom.java - apply other changes
This is to facilitate the comparison with diff in Github (using the diff between the second commit and the first commit).