2005-04-16 jrandom
* Migrated to Bouncycastle's SHA256 and HMAC implementations for efficiency
This commit is contained in:
@ -72,32 +72,28 @@ public class HMACSHA256Bench {
|
||||
}
|
||||
byte[] lmess = buf.toString().getBytes();
|
||||
|
||||
HMACSHA256Generator.Buffer sbuf = ctx.hmac().createBuffer(smess.length);
|
||||
HMACSHA256Generator.Buffer mbuf = ctx.hmac().createBuffer(mmess.length);
|
||||
HMACSHA256Generator.Buffer lbuf = ctx.hmac().createBuffer(lmess.length);
|
||||
|
||||
// warm up the engines
|
||||
ctx.hmac().calculate(key, smess, sbuf);
|
||||
ctx.hmac().calculate(key, mmess, mbuf);
|
||||
ctx.hmac().calculate(key, lmess, lbuf);
|
||||
ctx.hmac().calculate(key, smess);
|
||||
ctx.hmac().calculate(key, mmess);
|
||||
ctx.hmac().calculate(key, lmess);
|
||||
|
||||
long before = System.currentTimeMillis();
|
||||
for (int x = 0; x < times; x++)
|
||||
ctx.hmac().calculate(key, smess, sbuf);
|
||||
ctx.hmac().calculate(key, smess);
|
||||
long after = System.currentTimeMillis();
|
||||
|
||||
display(times, before, after, smess.length, "3 byte");
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
for (int x = 0; x < times; x++)
|
||||
ctx.hmac().calculate(key, mmess, mbuf);
|
||||
ctx.hmac().calculate(key, mmess);
|
||||
after = System.currentTimeMillis();
|
||||
|
||||
display(times, before, after, mmess.length, "2KB");
|
||||
|
||||
before = System.currentTimeMillis();
|
||||
for (int x = 0; x < times; x++)
|
||||
ctx.hmac().calculate(key, lmess, lbuf);
|
||||
ctx.hmac().calculate(key, lmess);
|
||||
after = System.currentTimeMillis();
|
||||
|
||||
display(times, before, after, lmess.length, "10KB");
|
||||
|
@ -68,11 +68,6 @@ public class SHA256Bench {
|
||||
}
|
||||
byte[] lmess = buf.toString().getBytes();
|
||||
|
||||
SHA256EntryCache cache = new SHA256EntryCache();
|
||||
SHA256EntryCache.CacheEntry scache = cache.acquire(smess.length);
|
||||
SHA256EntryCache.CacheEntry mcache = cache.acquire(mmess.length);
|
||||
SHA256EntryCache.CacheEntry lcache = cache.acquire(lmess.length);
|
||||
|
||||
// warm up the engines
|
||||
SHA256Generator.getInstance().calculateHash(smess);
|
||||
SHA256Generator.getInstance().calculateHash(mmess);
|
||||
@ -89,34 +84,10 @@ public class SHA256Bench {
|
||||
Hash l = cacheOnly ? null : SHA256Generator.getInstance().calculateHash(lmess);
|
||||
long endlong = System.currentTimeMillis();
|
||||
|
||||
// now do it with caching
|
||||
Hash s1 = SHA256Generator.getInstance().calculateHash(smess, 0, smess.length, scache);
|
||||
long endshortstartmed1 = System.currentTimeMillis();
|
||||
Hash m1 = SHA256Generator.getInstance().calculateHash(mmess, 0, mmess.length, mcache);
|
||||
long endmedstartlong1 = System.currentTimeMillis();
|
||||
Hash l1 = SHA256Generator.getInstance().calculateHash(lmess, 0, lmess.length, lcache);
|
||||
long endlong1 = System.currentTimeMillis();
|
||||
|
||||
if (cacheOnly) {
|
||||
// dont verify
|
||||
} else {
|
||||
if (!s.equals(s1) || !m.equals(m1) || !l.equals(l1)) {
|
||||
System.err.println("*ERR* match failed on " + x
|
||||
+ "s="+ s.equals(s1) + " m=" + m.equals(m1)
|
||||
+ " l=" + l.equals(l1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//System.out.print(".");
|
||||
shorttime += endshortstartmed - startshort;
|
||||
shorttime += endshortstartmed - startshort;
|
||||
medtime += endmedstartlong - endshortstartmed;
|
||||
longtime += endlong - endmedstartlong;
|
||||
|
||||
shorttime1 += endshortstartmed1 - endlong;
|
||||
medtime1 += endmedstartlong1 - endshortstartmed1;
|
||||
longtime1 += endlong1 - endmedstartlong1;
|
||||
|
||||
if ((minShort == 0) && (minMed == 0) && (minLong == 0) ) {
|
||||
minShort = endshortstartmed - startshort;
|
||||
maxShort = endshortstartmed - startshort;
|
||||
@ -124,13 +95,6 @@ public class SHA256Bench {
|
||||
maxMed = endmedstartlong - endshortstartmed;
|
||||
minLong = endlong - endmedstartlong;
|
||||
maxLong = endlong - endmedstartlong;
|
||||
|
||||
minShort1 = endshortstartmed1 - endlong;
|
||||
maxShort1 = endshortstartmed1 - endlong;
|
||||
minMed1 = endmedstartlong1 - endshortstartmed1;
|
||||
maxMed1 = endmedstartlong1 - endshortstartmed1;
|
||||
minLong1 = endlong1 - endmedstartlong1;
|
||||
maxLong1 = endlong1 - endmedstartlong1;
|
||||
} else {
|
||||
if (minShort > endshortstartmed - startshort) minShort = endshortstartmed - startshort;
|
||||
if (maxShort < endshortstartmed - startshort) maxShort = endshortstartmed - startshort;
|
||||
@ -138,23 +102,12 @@ public class SHA256Bench {
|
||||
if (maxMed < endmedstartlong - endshortstartmed) maxMed = endmedstartlong - endshortstartmed;
|
||||
if (minLong > endlong - endmedstartlong) minLong = endlong - endmedstartlong;
|
||||
if (maxLong < endlong - endmedstartlong) maxLong = endlong - endmedstartlong;
|
||||
|
||||
if (minShort1 > endshortstartmed1 - endlong) minShort1 = endshortstartmed1 - endlong;
|
||||
if (maxShort1 < endshortstartmed1 - endlong) maxShort1 = endshortstartmed1 - endlong;
|
||||
if (minMed1 > endmedstartlong1 - endshortstartmed1) minMed1 = endmedstartlong - endshortstartmed;
|
||||
if (maxMed1 < endmedstartlong1 - endshortstartmed1) maxMed1 = endmedstartlong - endshortstartmed;
|
||||
if (minLong1 > endlong1 - endmedstartlong1) minLong1 = endlong1 - endmedstartlong1;
|
||||
if (maxLong1 < endlong1 - endmedstartlong1) maxLong1 = endlong1 - endmedstartlong1;
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println("Short Message Time Average : " + (shorttime/times) + "\ttotal: " + shorttime + "\tmin: " + minShort + "\tmax: " + maxShort + "\tBps: " + (shorttime == 0 ? "NaN" : ""+(times*smess.length)/shorttime));
|
||||
System.out.println("Medium Message Time Average : " + (medtime/times) + "\ttotal: " + medtime + "\tmin: " + minMed + "\tmax: " + maxMed + "\tBps: " + (medtime == 0 ? "NaN" : ""+(times*mmess.length*1000)/medtime));
|
||||
System.out.println("Long Message Time Average : " + (longtime/times) + "\ttotal: " + longtime + "\tmin: " + minLong + "\tmax: " + maxLong + "\tBps: " + (longtime == 0 ? "NaN" : "" + (times*lmess.length*1000)/longtime));
|
||||
|
||||
System.out.println("Short Message Time (cache) : " + (shorttime1/times) + "\ttotal: " + shorttime1 + "\tmin: " + minShort1 + "\tmax: " + maxShort1 + "\tBps: " + (shorttime1 == 0 ? "NaN" : ""+(times*smess.length)/shorttime1));
|
||||
System.out.println("Medium Message Time (cache) : " + (medtime1/times) + "\ttotal: " + medtime1 + "\tmin: " + minMed1 + "\tmax: " + maxMed1 + "\tBps: " + (times*mmess.length*1000)/medtime1);
|
||||
System.out.println("Long Message Time (cache) : " + (longtime1/times) + "\ttotal: " + longtime1 + "\tmin: " + minLong1 + "\tmax: " + maxLong1 + "\tBps: " + (times*lmess.length*1000)/longtime1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user