Exemplo n.º 1
0
        /// <summary>
        /// 快速计时并且返回当前计时实例
        /// </summary>
        /// <param name="times"></param>
        /// <param name="action"></param>
        /// <param name="threadCount"></param>
        /// <returns></returns>
        public static CodeTimerAdvance Time(Int32 times, Action <Int32> action, int threadCount = 1)
        {
            CodeTimerAdvance timer = new CodeTimerAdvance
            {
                Times  = times,
                Action = action
            };

            timer.TimeOne();   //不要预热的话就注释
            timer.Time(threadCount);
            return(timer);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 计时,并用控制台输出行
        /// </summary>
        /// <param name="title"></param>
        /// <param name="times"></param>
        /// <param name="action"></param>
        /// <param name="threadCount"></param>
        public static void TimeByConsole(String title, Int32 times, Action <Int32> action, int threadCount = 1)
        {
            ConsoleColor currentForeColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("{0,16}:\r\n", title);

            CodeTimerAdvance timer = new CodeTimerAdvance
            {
                Times        = times,
                Action       = action,
                ShowProgress = true
            };


            Console.ForegroundColor = ConsoleColor.Yellow;

            //timer.TimeOne();   //不要预热的话就注释
            timer.Time(threadCount);

            Console.WriteLine(timer.ToString());

            Console.ForegroundColor = currentForeColor;
        }