Here are my RSA benchmark results:

Conclusion is that RSA key generation is expensive no matter what, but it's 
20x-40x worse on mono.

.NET 4.0, Win 8.1 VM inside a Mac, Debug build, 3 trials average:
1024    27 ms
2048    80 ms
3072    673 ms

.NET 4.0, Win 8.1 VM inside a Mac, Release build, 3 trials average:
1024    14 ms
2048    94 ms
3072    1,273 ms

Mono 3.2.5 on Mac OSX, compiled by VS Debug, 3 trials average:
1024    505 ms
2048    4,718 ms
3072    42,972 ms

Mono 3.2.5 on Mac OSX, compiled by VS Release, 3 trials average:
1024    883 ms
2048    8,310 ms
3072    40,284 ms

Mono 3.2.5 on Mac OSX, compiled by xbuild Debug, 3 trials average:
1024    894 ms
2048    5,756 ms
3072    35,273 ms

Mono 3.2.5 on Mac OSX, compiled by xbuild Release, 3 trials average:
1024    1,215 ms
2048    12,966 ms
3072    18,952 ms

Code to generate these results:

using System;
using System.Collections.Generic;
using System.Security.Cryptography;

namespace FunWithRSAKeys
{
    class Program
    {
        static void Main(string[] args)
        {
            const int numRuns = 3;
            long beforeTicks;
            long afterTicks;
            RSACryptoServiceProvider RSACSP;
            int[] keySizes = { 1024, 2048, 3072 };
            Dictionary<int, double[]> results = new Dictionary<int, double[]>();
            foreach (int keySize in keySizes)
                results[keySize] = new double[numRuns];

            for (int i = 0; i < numRuns; i++)
            {
                System.Console.WriteLine("-----------------------------");
                foreach (int keySize in keySizes)
                {
                    beforeTicks = DateTime.UtcNow.Ticks;
                    RSACSP = new RSACryptoServiceProvider(keySize);
                    RSACSP.ExportParameters(false);   // Minimum effort to 
guarantee key will actually be generated
                    afterTicks = DateTime.UtcNow.Ticks;
                    double seconds = (double)(afterTicks - beforeTicks) / 
(double)TimeSpan.TicksPerSecond;
                    results[keySize][i] = seconds;
                    System.Console.WriteLine(keySize.ToString() + " " + 
seconds.ToString());
                }
            }
            System.Console.WriteLine("----------------------------- Results");
            foreach(int keySize in keySizes)
            {
                System.Console.WriteLine(keySize.ToString() + " " + 
avg(results[keySize]).ToString());
            }
            System.Console.WriteLine("-----------------------------");
            System.Threading.Thread.Sleep(int.MaxValue);
        }
        static double avg(double[] values)
        {
            double result = 0;
            foreach (double value in values)
                result += value / values.Length;
            return result;
        }
    }
}
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to