Last active
April 10, 2020 09:53
-
-
Save peterhpchen/f82bb3f00f6738f432958295c9d3a0c1 to your computer and use it in GitHub Desktop.
Stopwatch Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Threading; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
Stopwatch stopWatch = new Stopwatch(); | |
stopWatch.Start(); | |
// 上面兩行可以改為下面一行 | |
// Stopwatch stopWatch = Stopwatch.StartNew(); | |
Thread.Sleep(1000); | |
stopWatch.Stop(); | |
Console.WriteLine(stopWatch.ElapsedMilliseconds); | |
stopWatch.Start(); | |
Thread.Sleep(1000); | |
stopWatch.Stop(); | |
Console.WriteLine(stopWatch.ElapsedMilliseconds); // 因沒有 Reset ,此時間會繼續累加 | |
stopWatch.Reset(); | |
stopWatch.Start(); | |
// 上面兩行可以改為下面一行 | |
// stopWatch.Restart(); | |
Thread.Sleep(1000); | |
stopWatch.Stop(); | |
Console.WriteLine(stopWatch.ElapsedMilliseconds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment