Exemplo n.º 1
0
        /// <summary>
        /// Collects benchmark stats for a specified binary operator
        /// </summary>
        /// <param name="f">The binary operator</param>
        /// <param name="min">The minimum operand value</param>
        /// <param name="max">The maximum operand value</param>
        /// <param name="oplabel">The name of the operation, excluding type info</param>
        /// <typeparam name="K">The primal operand type</typeparam>
        protected OpTime BenchmarkOp <K>(BinaryOp <K> f, string oplabel, K min, K max)
            where K : unmanaged
        {
            var buffer1 = new K[SampleSize];
            var buffer2 = new K[SampleSize];
            var sw      = stopwatch(false);
            var last    = default(K);

            for (var round = 0; round < RoundCount; round++)
            {
                for (var cycle = 0; cycle < CycleCount; cycle++)
                {
                    Random.StreamTo((min, max), buffer1.Length, ref buffer1[0]);
                    Random.StreamTo((min, max), buffer2.Length, ref buffer2[0]);

                    sw.Start();
                    for (var k = 0; k < buffer1.Length; k++)
                    {
                        last = f(buffer1[k], buffer2[k]);
                    }
                    sw.Stop();
                }
            }
            var    opname = oplabel + angled(type <K>().DisplayName());
            OpTime timing = (SampleSize * CycleCount * RoundCount, sw, opname);

            Collect(timing);
            return(timing);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Collects benchmark stats for worker that processes two sample arrays of the same data type
        /// </summary>
        /// <param name="min">The minimum operand value</param>
        /// <param name="max">The maximum operand value</param>
        /// <param name="oplabel">The name of the operation, excluding type info</param>
        /// <param name="worker">The sample processor to be measured</param>
        /// <typeparam name="K">The primal operand type</typeparam>
        protected OpTime Benchmark <K>(Action <K[], K[]> worker, string oplabel, K min, K max)
            where K : unmanaged
        {
            var buffer1 = new K[SampleSize];
            var buffer2 = new K[SampleSize];
            var sw      = stopwatch(false);

            for (var round = 0; round < RoundCount; round++)
            {
                for (var cycle = 0; cycle < CycleCount; cycle++)
                {
                    Random.StreamTo((min, max), buffer1.Length, ref buffer1[0]);
                    Random.StreamTo((min, max), buffer2.Length, ref buffer2[0]);

                    sw.Start();
                    worker(buffer1, buffer2);
                    sw.Stop();
                }
            }

            var    opname = oplabel + angled(type <K>().DisplayName());
            OpTime timing = (SampleSize * CycleCount * RoundCount, sw, opname);

            Collect(timing);
            return(timing);
        }
Exemplo n.º 3
0
 protected void TracePerf(OpTime time, int?labelPad = null)
 {
     if (TraceEnabled)
     {
         TracePerf(time.Format(labelPad));
     }
 }
Exemplo n.º 4
0
        void contract64f_bench()
        {
            var max = 250000ul;
            var n   = SampleSize;
            var sw  = stopwatch();
            var src = Random.Array <ulong>(n);

            sw.Start();
            for (var i = 0; i < n; i++)
            {
                contract(src[i], max);
            }
            sw.Stop();
            var time1 = OpTime.Define(n, snapshot(sw), "contract-f64");

            sw.Reset();
            sw.Start();
            for (var i = 0; i < n; i++)
            {
                src[i].Contract(max);
            }
            sw.Stop();
            var time2 = OpTime.Define(n, snapshot(sw), "contract-baseline");

            TracePerf((time1, time2));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Collects operation timing
        /// </summary>
        /// <param name="time">The time to collect</param>
        /// <param name="labelPad">For tracing, the width of the timing label</param>
        protected void Collect(OpTime time, int?labelPad = null)
        {
            Enqueue(time);

            if (TraceEnabled)
            {
                TracePerf(time.Format(labelPad));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Collects function evaluation timing
        /// </summary>
        /// <param name="f">The function to evaluate</param>
        /// <param name="label">The measurement label</param>
        /// <param name="labelPad">For tracing, the width of the measurement label</param>
        public void Measure(Func <int> f, [CallerMemberName] string label = null, int?labelPad = null)
        {
            var sw   = stopwatch();
            var ops  = f();
            var time = OpTime.Define(ops, snapshot(sw), label);

            Enqueue(time);

            if (TraceEnabled)
            {
                TracePerf(time.Format(labelPad));
            }
        }
Exemplo n.º 7
0
        public void bm_and_32x32x32_bench()
        {
            var sw = stopwatch(false);

            for (var i = 0; i < OpCount; i++)
            {
                var x = Random.BitMatrix(n32);
                var y = Random.BitMatrix(n32);
                sw.Start();
                var result = x & y;
                sw.Stop();
            }
            OpTime time = (OpCount, sw, "bm_and_32x32");

            Collect(time);
        }
Exemplo n.º 8
0
        protected OpTime Benchmark <T>(IPointSource <T> src, string opname = null)
            where T : struct
        {
            var last = default(T);
            var sw   = stopwatch();

            for (var cycle = 0; cycle < CycleCount; cycle++)
            {
                for (var i = 0; i < SampleSize; i++)
                {
                    last = src.Next();
                }
            }

            OpTime time = (CycleCount * SampleSize, sw, opname ?? $"{src.RngKind}<{type<T>().DisplayName()}>");

            Collect(time);
            return(time);
        }
Exemplo n.º 9
0
        void TestMrg32k3Ad()
        {
            var sw      = stopwatch();
            var rng     = new Mrg32K3Ad();
            var min     = int.MaxValue;
            var max     = int.MinValue;
            var cycles  = Pow2.T08;
            var samples = Pow2.T22;

            for (var cycle = 0; cycle < cycles; cycle++)
            {
                for (var i = 0; i < samples; i++)
                {
                    var next = rng.Next(0, int.MaxValue);
                    if (next < min)
                    {
                        min = next;
                    }
                    if (next > max)
                    {
                        max = next;
                    }
                }
                print('.');
                if (cycle != 0 && cycle % 80 == 0)
                {
                    print();
                }
            }
            print();

            OpTime time = (cycles * samples, sw, "MRG32k3u");

            print($"Min = {min}, Max = {max}");
            print(time);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Enqueues operation timing
 /// </summary>
 /// <param name="timing">The timing to enqueue</param>
 protected void Enqueue(OpTime timing)
 => OpTimes.Add(timing);