LoginSignup
19
13

More than 5 years have passed since last update.

Unity C#で処理時間を計測する

Last updated at Posted at 2017-11-24

環境

  • Unity 2017.2
  • VisualStudio 2015
  • Windows 10 64bit

実装

UnityにはSystem.Diagnostics.Stopwatchというクラスが用意されています。
これを使用し、時間を計測します。

今回はなぜかネームスペースをusingで呼び出した場合、Debugというクラスが重複してしまうようで、エラーが出てしまいました。
ですので以下のように記述します。

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
for(int i = 0; i < 60000; i ++){
    for(int j = 0; j < 60000; j++){
    }
}
sw.Stop();
Debug.Log(sw.ElapsedMilliseconds + "ms")

これでコンソールに処理時間が表示されます。
ElapsedMillisecondsの戻値はlongです。

19
13
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
19
13