1.从程序开始运行计算,到某一位置的运行时长
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
fun();
float time = Time.realtimeSinceStartup; //从程序开始到该位置的运行时长
}
void fun()
{
}
}
2.某一段代码或某一个函数的运行时长
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
fun();
float time = Time.realtimeSinceStartup; //fun()、到该位置的运行时间
fun1();
float time1 = Time.realtimeSinceStartup - time; //fun1()函数运行时间,做差实现
}
void fun()
{
}
void fun1()
{
}
}
3.某一段代码的运行时间,与2中的方法相同