public void CreateOgg() { try { double totalTime = 0.0; const int iterations = 1000; using (new CodeTimer("Combined")) { for (int i = 0; i < iterations; i++) { CodeTimer timer = new CodeTimer(); using (timer) { File.Create(new LocalFileAbstraction("samples/sample.ogg")); } totalTime += timer.ElapsedTime.TotalSeconds; } } Console.WriteLine("Average time: {0}", totalTime / iterations); } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// 计时。 /// </summary> /// <param name="times">次数。</param> /// <param name="action">测试项。</param> /// <returns></returns> public static CodeTimer Time(Int32 times, Action <Int32> action) { CodeTimer timer = new CodeTimer(); timer.Times = times; timer.Action = action; timer.TimeOne(); timer.Time(); return(timer); }
/// <summary> /// 计时,并用控制台输出行 /// </summary> /// <param name="title">标题。</param> /// <param name="times">次数。</param> /// <param name="action">测试项。</param> public static void TimeLine(String title, Int32 times, Action <Int32> action) { Console.Write("{0,16}:", title); CodeTimer timer = new CodeTimer(); timer.Times = times; timer.Action = action; timer.ShowProgress = true; ConsoleColor currentForeColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; timer.TimeOne(); timer.Time(); Console.WriteLine(timer.ToString()); Console.ForegroundColor = currentForeColor; }
/// <summary> /// 计时。 /// </summary> /// <param name="times">次数。</param> /// <param name="action">测试项。</param> /// <returns></returns> public static CodeTimer Time(Int32 times, Action<Int32> action) { CodeTimer timer = new CodeTimer(); timer.Times = times; timer.Action = action; timer.TimeOne(); timer.Time(); return timer; }
/// <summary> /// 计时,并用控制台输出行 /// </summary> /// <param name="title">标题。</param> /// <param name="times">次数。</param> /// <param name="action">测试项。</param> public static void TimeLine(String title, Int32 times, Action<Int32> action) { Console.Write("{0,16}:", title); CodeTimer timer = new CodeTimer(); timer.Times = times; timer.Action = action; timer.ShowProgress = true; ConsoleColor currentForeColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; timer.TimeOne(); timer.Time(); Console.WriteLine(timer.ToString()); Console.ForegroundColor = currentForeColor; }