Csharp/C Sharp by API/System.Diagnostics/Stopwatch
Содержание
Stopwatch.ElapsedMilliseconds
<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>
Stopwatch.ElapsedTicks
<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(sw.ElapsedTicks); sw.Reset(); sw.Start(); for (int i = 0; i < 1000; i++) { } sw.Stop(); Console.WriteLine("TryParse pattern took {0}ms", sw.ElapsedMilliseconds); }
}
</source>
Stopwatch.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>
Stopwatch.Start()
<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>