forked from I2P_Developers/i2p.i2p
measure keygen time in test
This commit is contained in:
@ -347,10 +347,10 @@ public class KeyGenerator {
|
|||||||
try { Thread.sleep(1000); } catch (InterruptedException ie) {}
|
try { Thread.sleep(1000); } catch (InterruptedException ie) {}
|
||||||
int runs = 200; // warmup
|
int runs = 200; // warmup
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
for (int i = 0; i <= 100; i++) {
|
for (SigType type : SigType.values()) {
|
||||||
SigType type = SigType.getByCode(i);
|
if (!type.isAvailable()) {
|
||||||
if (type == null)
|
System.out.println("Skipping unavailable: " + type);
|
||||||
break;
|
}
|
||||||
try {
|
try {
|
||||||
System.out.println("Testing " + type);
|
System.out.println("Testing " + type);
|
||||||
testSig(type, runs);
|
testSig(type, runs);
|
||||||
@ -365,9 +365,19 @@ public class KeyGenerator {
|
|||||||
|
|
||||||
private static void testSig(SigType type, int runs) throws GeneralSecurityException {
|
private static void testSig(SigType type, int runs) throws GeneralSecurityException {
|
||||||
byte src[] = new byte[512];
|
byte src[] = new byte[512];
|
||||||
|
double gtime = 0;
|
||||||
long stime = 0;
|
long stime = 0;
|
||||||
long vtime = 0;
|
long vtime = 0;
|
||||||
SimpleDataStructure keys[] = KeyGenerator.getInstance().generateSigningKeys(type);
|
SimpleDataStructure keys[] = null;
|
||||||
|
long st = System.nanoTime();
|
||||||
|
// RSA super slow, limit to 5
|
||||||
|
int genruns = (type.getBaseAlgorithm() == SigAlgo.RSA) ? Math.min(runs, 5) : runs;
|
||||||
|
for (int i = 0; i < genruns; i++) {
|
||||||
|
keys = KeyGenerator.getInstance().generateSigningKeys(type);
|
||||||
|
}
|
||||||
|
long en = System.nanoTime();
|
||||||
|
gtime = ((en - st) / (1000*1000d)) / genruns;
|
||||||
|
System.out.println(type + " key gen " + genruns + " times: " + gtime + " ms each");
|
||||||
SigningPublicKey pubkey = (SigningPublicKey) keys[0];
|
SigningPublicKey pubkey = (SigningPublicKey) keys[0];
|
||||||
SigningPrivateKey privkey = (SigningPrivateKey) keys[1];
|
SigningPrivateKey privkey = (SigningPrivateKey) keys[1];
|
||||||
SigningPublicKey pubkey2 = getSigningPublicKey(privkey);
|
SigningPublicKey pubkey2 = getSigningPublicKey(privkey);
|
||||||
|
Reference in New Issue
Block a user