static void Benchmark(object obj, uint iterations, string suffix = null)
        {
            var bench   = new BenchShark(true);
            var result  = bench.EvaluateDecoratedTasks(obj, iterations);
            var results = result.FastestEvaluations.Select(x =>
            {
                var series = x.Iterations.Select(it => (double)it.ElapsedTicks).ToArray();
                Array.Sort(series);
                var summary = SortedArrayStatistics.FiveNumberSummary(series);
                var ms      = ArrayStatistics.MeanStandardDeviation(series);
                return(new { x.Name, Mean = ms.Item1, StdDev = ms.Item2, Min = summary[0], Q1 = summary[1], Median = summary[2], Q3 = summary[3], Max = summary[4] });
            }).ToArray();
            var top     = results[0];
            var managed = results.Single(x => x.Name.StartsWith("Managed"));
            var label   = string.IsNullOrEmpty(suffix) ? obj.GetType().FullName : string.Concat(obj.GetType().FullName, ": ", suffix);

            results.Select(x => new
            {
                x.Name,
                Mean           = Math.Round(x.Mean), StdDev = Math.Round(x.StdDev),
                Min            = Math.Round(x.Min), Q1 = Math.Round(x.Q1), Median = Math.Round(x.Median), Q3 = Math.Round(x.Q3), Max = Math.Round(x.Max),
                TopSlowdown    = Math.Round(x.Median / top.Median, 2),
                ManagedSpeedup = Math.Round(managed.Median / x.Median, 2)
            }).Dump(label);
        }
        public void EvaluateDecoratedTasks_Obj_TenIteration()
        {
            // Arrange
            var shark = new BenchShark(true) { EnableUnoptimizedEvaluations = true };
            SetupEnvironment();

            // Act
            var methods = shark.EvaluateDecoratedTasks(this, 10);

            // Assert
            Assert.AreEqual(3, methods.Evaluations.Count());
            Assert.AreNotEqual(methods.Evaluations.ElementAt(0), methods.Evaluations.ElementAt(1));
            Assert.AreEqual(11, FooRun); // one execution to jut the function, second to evaluate
            Assert.AreEqual(11, BarRun);
            Assert.AreEqual(11, StaticFoobarRun);
        }
Beispiel #3
0
        public void EvaluateDecoratedTasks_Obj_OneIteration()
        {
            // Arrange
            var shark = new BenchShark(true)
            {
                EnableUnoptimizedEvaluations = true
            };

            SetupEnvironment();

            // Act
            var methods = shark.EvaluateDecoratedTasks(this, 1);

            // Assert
            Assert.AreEqual(3, methods.Evaluations.Count());
            Assert.AreNotEqual(methods.Evaluations.ElementAt(0), methods.Evaluations.ElementAt(1));
            Assert.AreEqual(2, FooRun); // one execution to jut the function, second to evaluate
            Assert.AreEqual(2, BarRun);
            Assert.AreEqual(2, StaticFoobarRun);
        }
Beispiel #4
0
        public void EvaluateDecoratedTasks_Type_TenIteration()
        {
            // Arrange
            var shark = new BenchShark(true)
            {
                EnableUnoptimizedEvaluations = true
            };

            SetupEnvironment();

            // Act
            var methods = shark.EvaluateDecoratedTasks <ReflectionEvaluationTests>(10);

            // Assert
            Assert.AreEqual(3, methods.Evaluations.Count());
            Assert.AreNotEqual(methods.Evaluations.ElementAt(0), methods.Evaluations.ElementAt(1));
            Assert.AreEqual(11, FooRun);
            Assert.AreEqual(11, BarRun);
            Assert.AreEqual(11, StaticFoobarRun);
        }
Beispiel #5
0
 static void Benchmark(object obj, uint iterations, string suffix = null)
 {
     var bench = new BenchShark(true);
     var result = bench.EvaluateDecoratedTasks(obj, iterations);
     var results = result.FastestEvaluations.Select(x =>
     {
         var series = x.Iterations.Select(it => (double)it.ElapsedTicks).ToArray();
         Array.Sort(series);
         var summary = SortedArrayStatistics.FiveNumberSummary(series);
         var ms = ArrayStatistics.MeanStandardDeviation(series);
         return new { x.Name, Mean = ms.Item1, StdDev = ms.Item2, Min = summary[0], Q1 = summary[1], Median = summary[2], Q3 = summary[3], Max = summary[4] };
     }).ToArray();
     var top = results[0];
     var managed = results.Single(x => x.Name.StartsWith("Managed"));
     var label = string.IsNullOrEmpty(suffix) ? obj.GetType().FullName : string.Concat(obj.GetType().FullName, ": ", suffix);
     results.Select(x => new
     {
         x.Name,
         Mean = Math.Round(x.Mean), StdDev = Math.Round(x.StdDev),
         Min = Math.Round(x.Min), Q1 = Math.Round(x.Q1), Median = Math.Round(x.Median), Q3 = Math.Round(x.Q3), Max = Math.Round(x.Max),
         TopSlowdown = Math.Round(x.Median/top.Median, 2),
         ManagedSpeedup = Math.Round(managed.Median/x.Median, 2)
     }).Dump(label);
 }
        public void EvaluateDecoratedTasks_Type_OneIteration()
        {
            // Arrange
            var shark = new BenchShark(true) {EnableUnoptimizedEvaluations = true};
            SetupEnvironment();

            // Act
            var methods = shark.EvaluateDecoratedTasks<ReflectionEvaluationTests>(1);

            // Assert
            Assert.AreEqual(3, methods.Evaluations.Count());
            Assert.AreNotEqual(methods.Evaluations.ElementAt(0), methods.Evaluations.ElementAt(1));
            Assert.AreEqual(2, FooRun);
            Assert.AreEqual(2, BarRun);
            Assert.AreEqual(2, StaticFoobarRun);
        }