using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < 100; i++)
{
UnityEngine.Debug.Log(i);
}
stopwatch.Stop();
UnityEngine.Debug.Log("ms=" + stopwatch.ElapsedMilliseconds);
}
}
![]()
本博客介绍了一个简单的Unity脚本,该脚本利用C#中的Stopwatch类来测量执行100次循环的总时间。通过记录每轮循环前后的毫秒数,可以有效地评估代码的执行效率。
766

被折叠的 条评论
为什么被折叠?



