Ejemplo n.º 1
0
    private static long OutterBenchmark(BenchmarkMethod method, long time, long warmups, long iters)
    {
        TimeReg timeReg = new TimeReg();

        Round(method, time, warmups, timeReg, "# Warmup ");
        return(Round(method, time, iters, timeReg, ""));
    }
Ejemplo n.º 2
0
        public static void Main1()
        {
            BenchmarkMethod bm  = new BenchmarkMethod(MStatic);
            DelegateDemo    t   = new DelegateDemo();
            BenchmarkMethod bm1 = new BenchmarkMethod(t.MInstance);

            bm.Invoke();
            bm1();

            if (bm.Target == null)
            {
                Console.WriteLine("Static");
            }
            else
            {
                Console.WriteLine("Instance, type = {0}", bm.Target.GetType());
            }
            Console.WriteLine("Method = {0}", bm.Method.Name);

            if (bm1.Target == null)
            {
                Console.WriteLine("Static");
            }
            else
            {
                Console.WriteLine("Instance, type = {0}", bm1.Target.GetType());
            }
            Console.WriteLine("Method = {0}", bm1.Method.Name);
        }
Ejemplo n.º 3
0
    public static void Benchmark(BenchmarkMethod method, String title, long time, long numWarmups, long numIters)
    {
        Console.WriteLine("\n:: BENCHMARKING {0} ::", title);
        long numOps = OutterBenchmark(method, time, numWarmups, numIters);

        Console.WriteLine("\nResult: {0} ops/s\t{1,8:0.00} ns\n", numOps, (1.0 / numOps) * 1.0e9);
    }
Ejemplo n.º 4
0
        private static long Round(BenchmarkMethod method, long time, long iters, TimeReg timeReg, string msg)
        {
            long bestNumOps = 0;
            long numOps;

            for (long i = 1; i <= iters; ++i)
            {
                Console.Write("{0}Iteration {1,2}: ", msg, i);
                InnerBenchmark(method, time, timeReg);
                numOps = (long)((double)timeReg.ops / timeReg.time * 1000);   // numOps = n. operacoes /s = frequencia

                if (numOps > bestNumOps)
                {
                    bestNumOps = numOps;
                }
                // periodo = 1 / frequencia
                // periodo (nanosegundos) = (1 / frequencia) * 10^9
                Console.WriteLine("{0} ops/s\t{1,8:0.00} ns", numOps, 1.0 / numOps * 1.0e9);
                Collect();
                // No final de cada iteracao existe um GC.Collect() para limpar objetos temporarios
                // que foram criados durante a iteracao.
                // Usado para evitar que ocorra um GC.Collect() a meio das proximas
                // iteracoes, o que poderia influenciar o tempo do teste de desempenho
            }

            return(bestNumOps);
        }
Ejemplo n.º 5
0
        private static void InnerBenchmark(BenchmarkMethod method, long time, TimeReg timeReg)
        {
            long ops = 0;
            long begTime = Environment.TickCount, curTime, endTime = begTime + time;

            do
            {
                method.Invoke();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                ops += 32; // Usado para diminuir a frequencia com que Environment.TickCount e' chamado

                /*
                 * method();
                 * ops++;
                 */

                curTime = Environment.TickCount; // Environment.TickCount devolve tempo decorrido em milisegundos
            } while (curTime < endTime);

            timeReg.ops  = ops;
            timeReg.time = curTime - begTime;
        }
Ejemplo n.º 6
0
        public (TimeSpan, object) Benchmark(BenchmarkMethod method)
        {
            Stopwatch sw0 = new Stopwatch();

            sw0.Start();
            var result = method();

            sw0.Stop();
            TimeSpan elapsed = sw0.Elapsed;

            Console.WriteLine($"Elapsed={elapsed} Sum={result}");
            return(elapsed, result);
        }
Ejemplo n.º 7
0
        public static void DoBenchmark(BenchmarkMethod method, int elementsToHash, int loops, bool positive)
        {
            Console.WriteLine("[{0} > 0 == {3}] Number of elements: {1}, Loops: {2}", method.Method.Name, elementsToHash, loops, positive);
            long time = 0;

            for (int i = 0; i < loops; i++)
            {
                long temp = method(elementsToHash, positive);
                time += temp;
            }

            float average = (float)time / loops;

            Console.WriteLine("[{0}] Time: {1}ms elements/ms: {2}", method.Method.Name, average, elementsToHash / average);
        }
Ejemplo n.º 8
0
    private static void InnerBenchmark(BenchmarkMethod method, long time, TimeReg timeReg)
    {
        long ops = 0;
        long begTime = Environment.TickCount, curTime, endTime = begTime + time;

        do
        {
            method(); method(); method(); method(); method(); method(); method(); method();
            method(); method(); method(); method(); method(); method(); method(); method();
            method(); method(); method(); method(); method(); method(); method(); method();
            method(); method(); method(); method(); method(); method(); method(); method();
            ops    += 32;
            curTime = Environment.TickCount;
        } while (curTime < endTime);
        timeReg.ops  = ops;
        timeReg.time = curTime - begTime;
    }
Ejemplo n.º 9
0
    private static long Round(BenchmarkMethod method, long time, long iters, TimeReg timeReg, string msg)
    {
        long bestNumOps = 0;
        long numOps;

        for (long i = 1; i <= iters; ++i)
        {
            Console.Write("{0}Iteration {1,2}: ", msg, i);
            InnerBenchmark(method, time, timeReg);
            numOps = (long)((((double)timeReg.ops) / timeReg.time) * 1000);
            if (numOps > bestNumOps)
            {
                bestNumOps = numOps;
            }
            Console.WriteLine("{0} ops/s\t{1,8:0.00} ns", numOps, (1.0 / numOps) * 1.0e9);
            Collect();
        }
        return(bestNumOps);
    }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            try
            {
                DateTime startTime = DateTime.Now;

                // first arg is job name, 2nd is params
                string jobName   = "";
                string paramsStr = "";
                if (args.Length > 0)
                {
                    jobName   = args[0].Trim();
                    paramsStr = args[1].Trim();
                }
                else
                {
                    //??? output error and exit
                }

                // 3rd arg is connection string override
                string dbConnStr;
                if (args.Length > 2)
                {
                    dbConnStr = args[2].Trim();
                }
                else
                {
                    dbConnStr = PerfRunner.Properties.Settings.Default.ConnStr.Trim();
                }

                JobWithBenchmarks j = PerfDb.ReadJobBenchmarkFromDb(dbConnStr, jobName, paramsStr);

                if (j.BenchmarkList != null && j.BenchmarkList.Count > 0)
                {
                    int totalRunCount = 0;
                    for (int i = 0; i < j.BenchmarkList.Count; i++)
                    {
                        int cnt = j.RunCount * j.BenchmarkList[i].CountN;
                        totalRunCount += cnt;
                    }

                    OrderAndIndex[] runOrderArray = new OrderAndIndex[totalRunCount];

                    Random rand = new Random(89);

                    int n = 0;
                    for (int i = 0; i < j.BenchmarkList.Count; i++)
                    {
                        int cnt  = j.RunCount;
                        int minN = j.BenchmarkList[i].MinN;
                        int maxN = j.BenchmarkList[i].MaxN;
                        int byN  = j.BenchmarkList[i].ByN;

                        for (int k = 0; k < cnt; k++)
                        {
                            for (int N = minN; N <= maxN; N += byN)
                            {
                                runOrderArray[n++] = new OrderAndIndex(rand.Next(int.MinValue, int.MaxValue), i, N);
                            }
                        }
                    }
                    Array.Sort(runOrderArray, new CompareOrderAndIndex());

                    EnvironmentInfo environInfo  = PerfUtil.GetEnvironmentInfo();
                    int             runID        = PerfDb.InsertRun(dbConnStr, j.JobID, j.Params, j.JobName, j.JobDescription, "", environInfo);
                    int             everyTenth   = runOrderArray.Length / 10;
                    int             nextTenth    = everyTenth;
                    int             nextPct      = 10;
                    DateTime        runStartTime = DateTime.Now;
                    Console.WriteLine("Starting Job: " + jobName + ", with Params: " + paramsStr + ", at: " + runStartTime.ToString("h:mm.s tt"));
                    for (int i = 0; i < runOrderArray.Length; i++)
                    {
                        BenchmarkMethod b = j.BenchmarkList[runOrderArray[i].index];
                        PerfUtil.StartProgramWithArguments_DbNAndMaxN(b.ExecutableFileName, dbConnStr, runID, b.BenchmarkMethodID, runOrderArray[i].n, b.MaxN);
                        if (i == nextTenth)
                        {
                            DateTime timeNow = DateTime.Now;
                            TimeSpan ts      = timeNow - runStartTime;
                            Console.WriteLine("Percent Done: " + nextPct.ToString("N0") + "%, Total Minutes So Far = " + ts.TotalMinutes.ToString("N2"));
                            nextTenth += everyTenth;
                            nextPct   += 10;
                        }
                    }
                    DateTime timeNowDone = DateTime.Now;
                    TimeSpan tsDone      = timeNowDone - runStartTime;
                    Console.WriteLine("Finished: Total Minutes = " + tsDone.TotalMinutes.ToString("N2"));
                }
            }
            catch (Exception ex)
            {
                PerfUtil.OutputError(ex);
                Console.ReadKey();
            }
        }