summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-10 18:51:01 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-10 18:51:01 +0700
commit866d0a4ad092c3e40bf6eb7432cfc6c5ae8b03b4 (patch)
treea10927fb2b14b668425fc343f146de6be7357028 /crypto
parentAdd MultiplyAddToExt method to fields (diff)
downloadBouncyCastle.NET-ed25519-866d0a4ad092c3e40bf6eb7432cfc6c5ae8b03b4.tar.xz
Adapt performance test to exclude outliers form average
Diffstat (limited to 'crypto')
-rw-r--r--crypto/test/src/math/ec/test/ECPointPerformanceTest.cs47
1 files changed, 32 insertions, 15 deletions
diff --git a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
index 69d6823e1..72ab839b3 100644
--- a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
+++ b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
@@ -24,8 +24,9 @@ namespace Org.BouncyCastle.Math.EC.Tests
     [TestFixture, Explicit]
     public class ECPointPerformanceTest
     {
-        public const int PRE_ROUNDS = 100;
-        public const int NUM_ROUNDS = 1000;
+        internal const int MULTS_PER_ROUND = 100;
+        internal const int PRE_ROUNDS = 1;
+        internal const int NUM_ROUNDS = 10;
 
         private static string[] COORD_NAMES = new string[]{ "AFFINE", "HOMOGENEOUS", "JACOBIAN", "JACOBIAN-CHUDNOVSKY",
             "JACOBIAN-MODIFIED", "LAMBDA-AFFINE", "LAMBDA-PROJECTIVE", "SKEWED" };
@@ -100,28 +101,44 @@ namespace Org.BouncyCastle.Math.EC.Tests
             ECPoint p = g;
             for (int i = 1; i <= PRE_ROUNDS; i++)
             {
-                BigInteger k = ks[ki];
-                p = g.Multiply(k);
-                if (++ki == ks.Length)
+                for (int j = 0; j < MULTS_PER_ROUND; ++j)
                 {
-                    ki = 0;
-                    g = p;
+                    BigInteger k = ks[ki];
+                    p = g.Multiply(k);
+                    if (++ki == ks.Length)
+                    {
+                        ki = 0;
+                        g = p;
+                    }
                 }
             }
-            long startTime = DateTimeUtilities.CurrentUnixMs();
+
+            double minElapsed = Double.MaxValue, maxElapsed = Double.MinValue, totalElapsed = 0.0;
+
             for (int i = 1; i <= NUM_ROUNDS; i++)
             {
-                BigInteger k = ks[ki];
-                p = g.Multiply(k);
-                if (++ki == ks.Length)
+                long startTime = DateTimeUtilities.CurrentUnixMs();
+
+                for (int j = 0; j < MULTS_PER_ROUND; ++j)
                 {
-                    ki = 0;
-                    g = p;
+                    BigInteger k = ks[ki];
+                    p = g.Multiply(k);
+                    if (++ki == ks.Length)
+                    {
+                        ki = 0;
+                        g = p;
+                    }
                 }
+
+                long endTime = DateTimeUtilities.CurrentUnixMs();
+
+                double roundElapsed = (double)(endTime - startTime);
+                minElapsed = System.Math.Min(minElapsed, roundElapsed);
+                maxElapsed = System.Math.Max(maxElapsed, roundElapsed);
+                totalElapsed += roundElapsed;
             }
-            long endTime = DateTimeUtilities.CurrentUnixMs();
 
-            return (double)(endTime - startTime) / NUM_ROUNDS;
+            return (totalElapsed - minElapsed - maxElapsed) / (NUM_ROUNDS - 2) / MULTS_PER_ROUND;
         }
 
         [Test]