diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-14 13:33:39 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-14 13:33:39 +0700 |
commit | ee4dbac875b551be255666775056e7c7efe3af95 (patch) | |
tree | 2a310da59b5ead3ad8cb93e94680e51813905dba | |
parent | Optimize squaring by inlining the ShiftUpBit (diff) | |
download | BouncyCastle.NET-ed25519-ee4dbac875b551be255666775056e7c7efe3af95.tar.xz |
Change primary measurement to multiplication rate using fixed-duration rounds
-rw-r--r-- | crypto/test/src/math/ec/test/ECPointPerformanceTest.cs | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs index daa08c219..04bc43716 100644 --- a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs +++ b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs @@ -24,8 +24,10 @@ namespace Org.BouncyCastle.Math.EC.Tests [TestFixture, Explicit] public class ECPointPerformanceTest { - internal const int MULTS_PER_ROUND = 100; - internal const int PRE_ROUNDS = 2; + internal const int MILLIS_PER_ROUND = 200; + internal const int MILLIS_WARMUP = 1000; + + internal const int MULTS_PER_CHECK = 16; internal const int NUM_ROUNDS = 10; private static string[] COORD_NAMES = new string[]{ "AFFINE", "HOMOGENEOUS", "JACOBIAN", "JACOBIAN-CHUDNOVSKY", @@ -72,18 +74,25 @@ namespace Org.BouncyCastle.Math.EC.Tests g = c.ImportPoint(G); } - double avgDuration = RandMult(random, g, n); + double avgRate = RandMult(random, g, n); string coordName = COORD_NAMES[coord]; StringBuilder sb = new StringBuilder(); sb.Append(" "); sb.Append(coordName); - for (int j = coordName.Length; j < 30; ++j) + for (int j = sb.Length; j < 28; ++j) { sb.Append(' '); } sb.Append(": "); - sb.Append(avgDuration); - sb.Append("ms"); + sb.Append(avgRate); + sb.Append(" mults/sec"); + for (int j = sb.Length; j < 64; ++j) + { + sb.Append(' '); + } + sb.Append('('); + sb.Append(1000.0 / avgRate); + sb.Append(" millis/mult)"); Console.WriteLine(sb.ToString()); } } @@ -99,9 +108,12 @@ namespace Org.BouncyCastle.Math.EC.Tests int ki = 0; ECPoint p = g; - for (int i = 1; i <= PRE_ROUNDS; i++) + { - for (int j = 0; j < MULTS_PER_ROUND; ++j) + long startTime = DateTimeUtilities.CurrentUnixMs(); + long goalTime = startTime + MILLIS_WARMUP; + + do { BigInteger k = ks[ki]; p = g.Multiply(k); @@ -114,37 +126,48 @@ namespace Org.BouncyCastle.Math.EC.Tests ki = 0; } } + while (DateTimeUtilities.CurrentUnixMs() < goalTime); } - double minElapsed = Double.MaxValue, maxElapsed = Double.MinValue, totalElapsed = 0.0; + double minRate = Double.MaxValue, maxRate = Double.MinValue, totalRate = 0.0; for (int i = 1; i <= NUM_ROUNDS; i++) { long startTime = DateTimeUtilities.CurrentUnixMs(); + long goalTime = startTime + MILLIS_PER_ROUND; + long count = 0, endTime; - for (int j = 0; j < MULTS_PER_ROUND; ++j) + do { - BigInteger k = ks[ki]; - p = g.Multiply(k); - if ((ki & 1) != 0) + ++count; + + for (int j = 0; j < MULTS_PER_CHECK; ++j) { - g = p; + BigInteger k = ks[ki]; + p = g.Multiply(k); + if ((ki & 1) != 0) + { + g = p; + } + if (++ki == ks.Length) + { + ki = 0; + } } - if (++ki == ks.Length) - { - ki = 0; - } - } - long endTime = DateTimeUtilities.CurrentUnixMs(); + endTime = DateTimeUtilities.CurrentUnixMs(); + } + while (endTime < goalTime); double roundElapsed = (double)(endTime - startTime); - minElapsed = System.Math.Min(minElapsed, roundElapsed); - maxElapsed = System.Math.Max(maxElapsed, roundElapsed); - totalElapsed += roundElapsed; + double roundRate = count * MULTS_PER_CHECK * 1000L / roundElapsed; + + minRate = System.Math.Min(minRate, roundRate); + maxRate = System.Math.Max(maxRate, roundRate); + totalRate += roundRate; } - return (totalElapsed - minElapsed - maxElapsed) / (NUM_ROUNDS - 2) / MULTS_PER_ROUND; + return (totalRate - minRate - maxRate) / (NUM_ROUNDS - 2); } [Test] |