Exemplo n.º 1
0
        public static void BulkSpeedTest(HashInfo hashInfo)
        {
            Console.WriteLine("[BULK SPEED TEST]");
            Console.WriteLine($"Frequency: {s_Frequency / 1e6d:F2} MHz");
            Console.WriteLine($"Keys Length: {BST_SIZE} Bytes");
            Console.WriteLine($"Repetitions: {BST_TRIALS}");

            using (SpeedTestOptimizer())
            {
                for (Int32 i = 0; i < WARMUP_ITERATIONS; ++i)
                {
                    GetAverageSpeed(hashInfo, BST_SIZE, BST_TRIALS, 0);
                }

                Double[] speed = new Double[8];

                for (Int32 align = 0; align < 8; ++align)
                {
                    speed[align] = GetAverageSpeed(hashInfo, BST_SIZE, BST_TRIALS, align);
                    Console.WriteLine($" - Alignment {align}: {FormatSpeed(speed[align])}");
                }

                Console.WriteLine($" - Average Speed: {FormatSpeed(StatsUtilities.Mean(speed))}");
            }
        }
Exemplo n.º 2
0
        private static Double GetAverageSpeed(HashInfo hashInfo, Int32 length, Int32 repetitions, Int32 align)
        {
            RandomXS r = new RandomXS();

            Byte[] key = new Byte[length + 512];

            unsafe
            {
                fixed(Byte *pin = key)
                {
                    UInt64 pinValue   = (UInt64)pin;
                    UInt64 alignValue = ((pinValue + 255ul) & 0xFFFFFFFFFFFFFF00ul) + (UInt64)align;
                    Int32  offset     = (Int32)(alignValue - pinValue);

                    List <Double> results = new List <Double>(repetitions);

                    for (Int32 i = 0; i < repetitions; ++i)
                    {
                        r.NextBytes(key, offset, length);

                        Hash hash = hashInfo.Initializer((UInt32)i);

                        Double start = NativeMethods.GetTime();
                        hash.ComputeHash(key, offset, length);
                        Double end = NativeMethods.GetTime();

                        Double ms  = ((end - start + 1.0d) * 1000.0d) / s_Frequency;
                        Double bps = (length * 1000.0d) / ms;

                        if (bps >= 0.0d)
                        {
                            results.Add(bps);
                        }
                    }

                    Double mean      = StatsUtilities.Mean(results);
                    Double threshold = 2.0d * StatsUtilities.StandardDeviation(results, mean);

                    for (Int32 i = results.Count - 1; i >= 0; --i)
                    {
                        if (Math.Abs(results[i] - mean) > threshold)
                        {
                            results.RemoveAt(i);
                        }
                    }

                    return(StatsUtilities.Mean(results));
                }
            }
        }