Exemple #1
0
        public void DisplayAverage()
        {
            MapMethodToPerf elapsedTimePerMethod = perfList[perfList.Count - 1];

            WriteLine("Average:");
            foreach (CountPerMethod countPerMethod in elapsedTimePerMethod.Values)
            {
                WriteLine("{0}\t{1}ms", countPerMethod.name, (countPerMethod.totalElapsedTime / countPerMethod.countCall));
            }
        }
Exemple #2
0
        public void Run(MethodToRun run, bool displayBeginEnd)
        {
            String methodName = getMethodName(run);

            if (displayBeginEnd)
            {
                WriteLine("Begin [{0}]", methodName);
            }
            MapMethodToPerf perfMethod = getCurrentPerf();

            perfMethod.Start();
            perfList.Add(new MapMethodToPerf());
            run();
            perfList.RemoveAt(perfList.Count - 1);
            perfMethod.Stop();

            CountPerMethod countPerMethod;

            perfMethod.TryGetValue(run.Method, out countPerMethod);
            if (countPerMethod == null)
            {
                countPerMethod                  = new CountPerMethod();
                countPerMethod.name             = methodName;
                countPerMethod.totalElapsedTime = 0;
                countPerMethod.countCall        = 0;
                perfMethod.Add(run.Method, countPerMethod);
            }

            long elapsedTime = perfMethod.ElapsedMilliseconds;

            countPerMethod.totalElapsedTime += elapsedTime;
            countPerMethod.countCall++;
            if (displayBeginEnd)
            {
                WriteLine("End [{0}] computed in {1}ms", methodName, elapsedTime);
                WriteLine();
            }
            else
            {
                WriteLine("{0}\t computed in {1}ms", methodName, elapsedTime);
            }
        }