private bool Benchmark(Action action, int runs = 5, int warmup = 0, double threshold = 0.3)
        {
            var time = SimpleBenchmarking.BenchmarkTime(action, runs, warmup);

            var baselineMedian =
                _helper.GetBaselineAndStoreMeasurement("Grp5", "Unique-Test5", "ut5", "Median",
                                                       time.Median);

            var pass = ((baselineMedian - time.Median) / baselineMedian) > (threshold * -1);

            return(pass);
        }
示例#2
0
文件: Program.cs 项目: DickTse/Helper
        private static void DemoBenchmarkTimer()
        {
            Console.WriteLine("=============================================");
            Console.WriteLine("Demonstrating how to use BenchmarkTimer class");
            Console.WriteLine("=============================================");

            Console.WriteLine();
            const int benchmarkCycles = 100000000;

            SimpleBenchmarking.Benchmark("List<Int32>", () =>
            {
                List <Int32> l = new List <Int32>();
                for (int i = 0; i < benchmarkCycles; i++)
                {
                    l.Add(i);
                    int x = l[i];
                }
                l = null;
            });
            SimpleBenchmarking.Benchmark("List<object> of Int32", () =>
            {
                List <object> l = new List <object>();
                for (int i = 0; i < benchmarkCycles; i++)
                {
                    l.Add(i);
                    int x = (int)l[i];
                }
                l = null;
            });
            SimpleBenchmarking.Benchmark("List<string>", () =>
            {
                List <string> l = new List <string>();
                for (int i = 0; i < benchmarkCycles; i++)
                {
                    l.Add("X");
                    string s = l[i];
                }
                l = null;
            });
            SimpleBenchmarking.Benchmark("List<object> of string", () =>
            {
                List <object> l = new List <object>();
                for (int i = 0; i < benchmarkCycles; i++)
                {
                    l.Add("X");
                    string s = (string)l[i];
                }
                l = null;
            });
        }