LoginSignup
6
6

More than 5 years have passed since last update.

[.net c#]処理時間の計測

Posted at

VisualStudio c#で処理時間の計測を行う

今さら感がありますが、時々使うけど、細かい所を忘れちゃうので備忘録メモ。
.NET Framework 2.0以降で使用可能なStopwatchクラスを使用しての処理時間計測。

参考サイト様
http://dobon.net/vb/dotnet/system/stopwatch.html
http://www.remember-the-time.xyz/2010/04/visual-studio.html

sample
using System.Diagnostics;

//Stopwatchオブジェクトを作成する
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

//ストップウォッチを開始する
sw.Start();

//時間を計測したい処理を記載

//ストップウォッチを止める
sw.Stop();

//結果を表示する
Debug.WriteLine(sw.Elapsed);

参考サイト様では、Consoleへの出力サンプルソースが記載されていたが、
それだと表示されなかったので、出力先をDebugに変更して使用。
「出力ウィンドウ」は [表示] - [出力] にて表示。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6