-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #5053 - adding jmh to test SecureRandom algorithms
Signed-off-by: Joakim Erdfelt <[email protected]>
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
jetty-jmh/src/main/java/org/eclipse/jetty/util/jmh/SecureRandomBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.eclipse.jetty.util.jmh; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
@State(Scope.Benchmark) | ||
@Threads(4000) | ||
@Warmup(iterations = 4, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 4, time = 1, timeUnit = TimeUnit.SECONDS) | ||
public class SecureRandomBenchmark | ||
{ | ||
@Param({"NativePRNG", "NativePRNGNonBlocking", "SHA1PRNG"}) | ||
String algorithm; | ||
|
||
SecureRandom secureRandom; | ||
|
||
@Setup(Level.Trial) | ||
public void setupTrial() throws Exception | ||
{ | ||
secureRandom = SecureRandom.getInstance(algorithm); | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode({Mode.Throughput}) | ||
public void testWebSocketMask() throws Exception | ||
{ | ||
byte[] mask = new byte[4]; | ||
secureRandom.nextBytes(mask); | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode({Mode.Throughput}) | ||
public void testClientNonce() throws Exception | ||
{ | ||
byte[] mask = new byte[8]; | ||
secureRandom.nextBytes(mask); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException | ||
{ | ||
Options opt = new OptionsBuilder() | ||
.include(SecureRandomBenchmark.class.getSimpleName()) | ||
.forks(1) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
b0f68a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The results of this version on my machine ...
4 Threads
40 Threads
400 Threads
4000 Threads
b0f68a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for JDK 11 ...
4000 Threads