Exemple #1
0
        public void Dispose()
        {
            UInt64 elapsedCycles = CycleBench.Thread() - m_startCycles;
            Int64  elapsedTime   = Stopwatch.GetTimestamp() - m_startTime;
            Int64  milliseconds  = (elapsedTime * 1000) / Stopwatch.Frequency;

            if (false == String.IsNullOrEmpty(m_text))
            {
                ConsoleColor defColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Yellow;
                String title  = String.Format("\tOperation > {0} <", m_text);
                String gcInfo =
                    String.Format("\tGC(G0={2,4}, G1={3,4}, G2={4,4})\n\tTotal Time  {0,7:N0}ms {1,11:N0} Kc \n",
                                  milliseconds,
                                  elapsedCycles / 1000,
                                  GC.CollectionCount(0) - m_gen0Start,
                                  GC.CollectionCount(1) - m_get1Start,
                                  GC.CollectionCount(2) - m_gen2Start);

                Console.WriteLine(new String('*', gcInfo.Length));
                Console.WriteLine();
                Console.WriteLine(title);
                Console.WriteLine();
                Console.ForegroundColor = defColor;
                if (m_arr.Length > 1)
                {
                    Console.WriteLine(String.Format("\tRepeat times {0}", m_arr.Length));
                    Console.WriteLine(String.Format("\tBest Time {0} ms", m_arr.Min()));
                    Console.WriteLine(String.Format("\tWorst Time {0} ms", m_arr.Max()));
                    Console.WriteLine(String.Format("\tAvarage Time {0} ms", m_arr.Average()));
                }
                Console.WriteLine();
                Console.WriteLine(gcInfo);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(new String('*', gcInfo.Length));
                Console.ForegroundColor = ConsoleColor.Red;
                //Console.WriteLine("\t\t**** Press <ENTER> to Continue ****");
                Console.WriteLine(new String('*', gcInfo.Length));
                Console.ForegroundColor = defColor;
                //  Console.ReadKey(true);
            }
        }
Exemple #2
0
        /// <summary>
        /// The private constructor for the class.
        /// </summary>
        /// <param name="startFresh">
        /// If true, forces a GC in order to count just new garbage collections.
        /// </param>
        /// <param name="format">
        /// A composit text string.
        /// </param>
        /// <param name="args">
        /// An array of objects to write with <paramref name="text"/>.
        /// </param>
        private BenchPerformance(Boolean startFresh,
                                 String format,
                                 params Object[] args)
        {
            if (startFresh)
            {
                PrepareForOperation();
            }

            m_text = String.Format(format, args);

            m_gen0Start = GC.CollectionCount(0);
            m_get1Start = GC.CollectionCount(1);
            m_gen2Start = GC.CollectionCount(2);

            // Get the time before returning so that any code above doesn't
            // impact the time.
            m_startTime   = Stopwatch.GetTimestamp();
            m_startCycles = CycleBench.Thread();
        }