コード例 #1
0
        private static void MeasureAll(Action buildEva, int batchIterations, Action buildLambda, Action buildFun,
                                       Action calcEva, Action calcLambda, Action calcFun, Action buildNCalcPy, int batchCount)
        {
            Console.WriteLine("Start measuring");
            Console.WriteLine("Heating");
            BenchHelper.Measure(buildEva, batchIterations, out _);
            BenchHelper.Measure(buildLambda, batchIterations, out _);
            BenchHelper.Measure(buildFun, batchIterations, out _);
            BenchHelper.Measure(calcEva, batchIterations, out _);
            BenchHelper.Measure(calcLambda, batchIterations, out _);
            BenchHelper.Measure(calcFun, batchIterations, out _);
            BenchHelper.Measure(buildNCalcPy, batchIterations, out _);


            var buildEvaluateTs = TimeSpan.Zero;
            var buildlambdaTs   = TimeSpan.Zero;
            var buildFunTs      = TimeSpan.Zero;

            var calcEvaluateTs = TimeSpan.Zero;
            var calcLambdaTs   = TimeSpan.Zero;
            var calcFunTs      = TimeSpan.Zero;
            var bcPyTs         = TimeSpan.Zero;

            Console.WriteLine("Iterating");
            int i = 0;

            while (true)
            {
                i++;
                buildEvaluateTs += BenchHelper.Measure(buildEva, batchIterations, out var evaluateAlloc);
                buildlambdaTs   += BenchHelper.Measure(buildLambda, batchIterations, out var lambdaAlloc);
                buildFunTs      += BenchHelper.Measure(buildFun, batchIterations, out var funAlloc);
                calcEvaluateTs  += BenchHelper.Measure(calcEva, batchIterations, out var calcEvaluateAlloc);
                calcLambdaTs    += BenchHelper.Measure(calcLambda, batchIterations, out var calcLambdaAlloc);
                calcFunTs       += BenchHelper.Measure(calcFun, batchIterations, out var calcFunAlloc);
                bcPyTs          += BenchHelper.Measure(buildNCalcPy, batchIterations, out var bcPyAlloc);
                if (i > batchCount)
                {
                    i = 0;
                    Console.Clear();

                    int iterations = batchCount * batchIterations;

                    Console.WriteLine($"{iterations} iterations done");
                    PrintResult("build nfun    ", buildFunTs, iterations, funAlloc);
                    PrintResult("build evaluate", buildEvaluateTs, iterations, evaluateAlloc);
                    PrintResult("build lambda  ", buildlambdaTs, iterations, lambdaAlloc);
                    PrintResult("calc nfun    ", calcFunTs, iterations, calcFunAlloc);
                    PrintResult("calc evaluate", calcEvaluateTs, iterations, calcEvaluateAlloc);
                    PrintResult("calc lambda  ", calcLambdaTs, iterations, calcLambdaAlloc);
                    PrintResult("python       ", bcPyTs, iterations, bcPyAlloc);

                    buildFunTs = buildEvaluateTs = buildlambdaTs = calcFunTs = calcEvaluateTs = calcLambdaTs = bcPyTs = TimeSpan.Zero;
                }
            }
コード例 #2
0
 private static TimeSpan Measure(Action a) => BenchHelper.Measure(a, Iterations, out _);