Csharp/CSharp Tutorial/Date Time/Stopwatch

Материал из .Net Framework эксперт
Версия от 15:19, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Use Stopwatch: start, stop and reset

<source lang="csharp">using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.rupilerServices; using System.Threading; public class MainClass {

   public static void Main()
   {
       Stopwatch sw = new Stopwatch();
       sw.Start();
       for (int i = 0; i < 1000; i++)
       {
       }
       sw.Stop();
       Console.WriteLine("Parse pattern took {0}ms", sw.ElapsedMilliseconds);
       sw.Reset();
       sw.Start();
       for (int i = 0; i < 1000; i++)
       {
       }
       sw.Stop();
       Console.WriteLine("TryParse pattern took {0}ms", sw.ElapsedMilliseconds);
   }

}</source>

Parse pattern took 0ms
TryParse pattern took 0ms