Пример #1
0
        public static void Time(string name, int iteration, Action action)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }
            ConsoleColor foregroundColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(name);
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            int[] numArray = new int[GC.MaxGeneration + 1];
            for (int generation = 0; generation <= GC.MaxGeneration; ++generation)
            {
                numArray[generation] = GC.CollectionCount(generation);
            }
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            ulong cycleCount = CodeTimer.GetCycleCount();

            for (int index = 0; index < iteration; ++index)
            {
                action();
            }
            ulong num1 = CodeTimer.GetCycleCount() - cycleCount;

            stopwatch.Stop();
            Console.ForegroundColor = foregroundColor;
            Console.WriteLine("\tTime Elapsed:\t" + stopwatch.ElapsedMilliseconds.ToString("N0") + "ms");
            Console.WriteLine("\tCPU Cycles:\t" + num1.ToString("N0"));
            for (int generation = 0; generation <= GC.MaxGeneration; ++generation)
            {
                int num2 = GC.CollectionCount(generation) - numArray[generation];
                Console.WriteLine("\tGen " + (object)generation + ": \t\t" + (object)num2);
            }
            Console.WriteLine();
        }
Пример #2
0
 public static void Initialize()
 {
     Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
     Thread.CurrentThread.Priority = ThreadPriority.Highest;
     CodeTimer.Time("", 1, (Action)(() => { }));
 }
 public static void Initialize()
 {
     CodeTimer.Initialize();
 }