[Unity优化系列]“CustomSampler”,可以测量任意代码块的GC Alloc和执行时间
[Unity优化系列]“CustomSampler”,可以测量任意代码块的GC Alloc和执行时间,并在Profiler上显示
示例
using UnityEngine; using UnityEngine.Profiling; public class Example : MonoBehaviour { private void Start() { var sampler = CustomSampler.Create( "Pokemon" ); sampler.Begin(); for ( int i = 0; i < 10000; i++ ) { Debug.Log( "啊啊" ); } sampler.End(); } }
- 通过使用CustomSampler,可以测量任何代码或GC Alloc的执行时间并在Profiler中显示它。
- 与 Profiler.BeginSample 类似,但开销比Profiler.BeginSample少。