forked from I2P_Developers/i2p.i2p
Move benchmarks into core
This commit is contained in:
68
core/java/bench/net/i2p/crypto/AESBench.java
Normal file
68
core/java/bench/net/i2p/crypto/AESBench.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package net.i2p.crypto;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
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.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;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.SessionKey;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
||||
@Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS)
|
||||
@Fork(1)
|
||||
@State(Scope.Benchmark)
|
||||
public class AESBench {
|
||||
I2PAppContext ctx = I2PAppContext.getGlobalContext();
|
||||
SessionKey key;
|
||||
byte[] iv = new byte[16];
|
||||
byte[] origPT = new byte[1024];
|
||||
byte[] origCT = new byte[1024];
|
||||
byte[] encrypted = new byte[1024];
|
||||
byte[] decrypted = new byte[1024];
|
||||
|
||||
@Param({"512", "768", "1024"})
|
||||
public int len;
|
||||
|
||||
@Setup
|
||||
public void prepare() {
|
||||
key = ctx.keyGenerator().generateSessionKey();
|
||||
ctx.random().nextBytes(iv);
|
||||
ctx.random().nextBytes(origPT);
|
||||
ctx.aes().encrypt(origPT, 0, origCT, 0, key, iv, len);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void encrypt() {
|
||||
ctx.aes().encrypt(origPT, 0, encrypted, 0, key, iv, len);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void decrypt() {
|
||||
ctx.aes().decrypt(origCT, 0, decrypted, 0, key, iv, len);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(AESBench.class.getSimpleName())
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
||||
70
core/java/bench/net/i2p/crypto/ElGamalBench.java
Normal file
70
core/java/bench/net/i2p/crypto/ElGamalBench.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package net.i2p.crypto;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
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.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;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.PrivateKey;
|
||||
import net.i2p.data.PublicKey;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
||||
@Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS)
|
||||
@Fork(1)
|
||||
@State(Scope.Benchmark)
|
||||
public class ElGamalBench {
|
||||
I2PAppContext ctx = I2PAppContext.getGlobalContext();
|
||||
PublicKey pubkey;
|
||||
PrivateKey privkey;
|
||||
byte[] origPT;
|
||||
byte[] origCT;
|
||||
|
||||
@Setup
|
||||
public void prepare() {
|
||||
Object pair[] = KeyGenerator.getInstance().generatePKIKeypair();
|
||||
pubkey = (PublicKey) pair[0];
|
||||
privkey = (PrivateKey) pair[1];
|
||||
origPT = new byte[222];
|
||||
ctx.random().nextBytes(origPT);
|
||||
origCT = ctx.elGamalEngine().encrypt(origPT, pubkey);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public Object[] keygen() {
|
||||
return KeyGenerator.getInstance().generatePKIKeypair();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public byte[] encrypt() {
|
||||
return ctx.elGamalEngine().encrypt(origPT, pubkey);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public byte[] decrypt() {
|
||||
return ctx.elGamalEngine().decrypt(origCT, privkey);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(ElGamalBench.class.getSimpleName())
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
||||
78
core/java/bench/net/i2p/crypto/SHA256Bench.java
Normal file
78
core/java/bench/net/i2p/crypto/SHA256Bench.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package net.i2p.crypto;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
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.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;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Hash;
|
||||
|
||||
/**
|
||||
* Test the JVM's implementation for speed
|
||||
*
|
||||
* Old results (2011-05):
|
||||
* <ul>
|
||||
* <li>eeepc Atom
|
||||
* <li>100,000 runs
|
||||
* <li>MessageDigest.getInstance time was included
|
||||
* <li>One println included
|
||||
* <li>Also shows GNU impl time (removed in 0.9.28)
|
||||
* </ul><pre>
|
||||
* JVM strlen GNU ms JVM ms
|
||||
* Oracle 387 3861 3565
|
||||
* Oracle 40 825 635
|
||||
* Harmony 387 8082 5158
|
||||
* Harmony 40 4137 1753
|
||||
* JamVM 387 36301 34100
|
||||
* JamVM 40 7022 6016
|
||||
* gij 387 125833 4342
|
||||
* gij 40 22417 988
|
||||
* </pre>
|
||||
*/
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
||||
@Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS)
|
||||
@Fork(1)
|
||||
@State(Scope.Benchmark)
|
||||
public class SHA256Bench {
|
||||
I2PAppContext ctx = I2PAppContext.getGlobalContext();
|
||||
|
||||
@Param({"40", "387", "10240"})
|
||||
public int len;
|
||||
|
||||
byte[] data;
|
||||
|
||||
@Setup
|
||||
public void prepare() {
|
||||
data = new byte[len];
|
||||
ctx.random().nextBytes(data);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public Hash calculateHash() {
|
||||
return ctx.sha().calculateHash(data);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(SHA256Bench.class.getSimpleName())
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
||||
@@ -382,6 +382,66 @@
|
||||
<target name="fulltest" depends="test, test.report" />
|
||||
<!-- end unit tests -->
|
||||
|
||||
<!-- benchmarks -->
|
||||
<target name="jmhLibCheck">
|
||||
<!-- override to Ant home if not set -->
|
||||
<property name="jmh.home" value="${ant.home}/lib" />
|
||||
<fail message="Please set jmh.home to a directory containing the necessary JMH libraries. See build.properties for details.">
|
||||
<condition>
|
||||
<not>
|
||||
<and>
|
||||
<available file="${jmh.home}/jmh-core.jar" />
|
||||
<available file="${jmh.home}/jmh-generator-annprocess.jar" />
|
||||
<available file="${jmh.home}/jopt-simple.jar" />
|
||||
<available file="${jmh.home}/commons-math3.jar" />
|
||||
</and>
|
||||
</not>
|
||||
</condition>
|
||||
</fail>
|
||||
</target>
|
||||
|
||||
<target name="bench.compile" depends="compile, jmhLibCheck">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj_bench" />
|
||||
<javac srcdir="./bench" debug="true" source="${javac.version}" target="${javac.version}" deprecation="on"
|
||||
debuglevel="lines,vars,source"
|
||||
includeAntRuntime="false"
|
||||
destdir="./build/obj_bench" >
|
||||
<classpath>
|
||||
<pathelement location="${jmh.home}/jmh-core.jar" />
|
||||
<pathelement location="${jmh.home}/jmh-generator-annprocess.jar" />
|
||||
<pathelement location="./build/obj" />
|
||||
</classpath>
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="bench.jar" depends="bench.compile, bench.jarUpToDate, listChangedFiles" unless="bench.jar.uptodate" >
|
||||
<!-- set if unset -->
|
||||
<property name="workspace.changes.tr" value="" />
|
||||
<jar destfile="./build/i2p-benchmarks.jar" basedir="./build/obj_bench" >
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${build.built-by}" />
|
||||
<attribute name="Build-Date" value="${build.timestamp}" />
|
||||
<attribute name="Base-Revision" value="${workspace.version}" />
|
||||
<attribute name="Main-Class" value="org.openjdk.jmh.Main" />
|
||||
<attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
|
||||
<attribute name="X-Compile-Source-JDK" value="${javac.version}" />
|
||||
<attribute name="X-Compile-Target-JDK" value="${javac.version}" />
|
||||
</manifest>
|
||||
<zipfileset src="${jmh.home}/jmh-core.jar" excludes="**/META-INF/services/**" />
|
||||
<zipfileset src="${jmh.home}/jopt-simple.jar" />
|
||||
<zipfileset src="${jmh.home}/commons-math3.jar" />
|
||||
<fileset dir="./build/obj" includes="**/*.class" />
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="bench.jarUpToDate">
|
||||
<uptodate property="bench.jar.uptodate" targetfile="build/i2p-benchmarks.jar" >
|
||||
<srcfiles dir= "." includes="build/obj_bench/**/*.class" />
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="./build" />
|
||||
</target>
|
||||
|
||||
Reference in New Issue
Block a user