重複の可能性:
Is DateTime.Now the best way to measure a function's performance?
Stopwatch vs. using System.DateTime.Now for timing events.NETストップウォッチ - パフォーマンスペナルティ
私は可能な限り高速に実行するために必要なコードを持っています。実行時間を記録できるように、私はStopwatchクラスを使用します。私はストップウォッチが悪い方法でパフォーマンスに影響を与えるかもしれないと思う。多分DateTimeの違いを使用する方が効果的でしょうか?
パフォーマンスはどちらが良いと思いますか?
Stopwatch sw = new Stopwatch();
sw.Start();
int a = 5;
// Critical lines of code
long elapsedMs = se.Elapsed.TotalMilliseconds;
OR
DateTime startDate = DateTime.Now;
int a = 5;
// Critical lines of code
long elapsedMs = DateTime.Now.Subtract(startDate).TotalMilleseconds;
私はどちらも同じ結果をもたらすでしょう。矛盾する違い。 –
参照http://stackoverflow.com/questions/2923283/stopwatch-vs-using-system-datetime-now-for-timing-events – ccellar
参照:http://stackoverflow.com/questions/28637/is-datetime-現時点で最善の方法 - 機能測定 - パフォーマンス - tl; dr:ストップウォッチを使用します。 –