1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.crypto;
19
20 import java.util.concurrent.TimeUnit;
21
22 import org.apache.commons.crypto.cipher.CryptoCipherFactory;
23 import org.apache.commons.crypto.random.CryptoRandomFactory;
24 import org.openjdk.jmh.annotations.Benchmark;
25 import org.openjdk.jmh.annotations.BenchmarkMode;
26 import org.openjdk.jmh.annotations.Fork;
27 import org.openjdk.jmh.annotations.Measurement;
28 import org.openjdk.jmh.annotations.Mode;
29 import org.openjdk.jmh.annotations.OutputTimeUnit;
30 import org.openjdk.jmh.annotations.Threads;
31 import org.openjdk.jmh.annotations.Warmup;
32
33
34
35
36
37 @BenchmarkMode(Mode.AverageTime)
38 @Fork(value = 1, jvmArgs = "-server")
39 @Threads(1)
40 @Warmup(iterations = 10)
41 @Measurement(iterations = 20)
42 @OutputTimeUnit(TimeUnit.MILLISECONDS)
43 public class CryptoBenchmark extends AbstractBenchmark {
44
45 private static final String RANDOM_JAVA = CryptoRandomFactory.RandomProvider.JAVA.getClassName();
46 private static final String RANDOM_OS = CryptoRandomFactory.RandomProvider.OS.getClassName();
47 private static final String RANDOM_OPENSSL = CryptoRandomFactory.RandomProvider.OPENSSL.getClassName();
48
49 private static final String CIPHER_OPENSSL = CryptoCipherFactory.CipherProvider.OPENSSL.getClassName();
50 private static final String CIPHER_JCE = CryptoCipherFactory.CipherProvider.JCE.getClassName();
51
52 @Benchmark
53 public void RandomCreateOS() throws Exception {
54 getRandom(RANDOM_OS);
55 }
56
57 @Benchmark
58 public void RandomCreateJava() throws Exception {
59 getRandom(RANDOM_JAVA);
60 }
61
62 @Benchmark
63 public void RandomCreateOpenssl() throws Exception {
64 getRandom(RANDOM_OPENSSL);
65 }
66
67 @Benchmark
68 public void RandomTestOS() throws Exception {
69 random(RANDOM_OS);
70 }
71
72 @Benchmark
73 public void RandomTestJava() throws Exception {
74 random(RANDOM_JAVA);
75 }
76
77 @Benchmark
78 public void RandomTestOpenssl() throws Exception {
79 random(RANDOM_OPENSSL);
80 }
81
82
83 @Benchmark
84 public void CipherCreateJce() throws Exception {
85 getCipher(CIPHER_JCE);
86 }
87
88 @Benchmark
89 public void CipherTestJce() throws Exception {
90 encipher(CIPHER_JCE);
91 }
92
93 @Benchmark
94 public void CipherCreateOpenssl() throws Exception {
95 getCipher(CIPHER_OPENSSL);
96 }
97
98 @Benchmark
99 public void CipherTestOpenssl() throws Exception {
100 encipher(CIPHER_OPENSSL);
101 }
102
103 }