标签:调用 top color watch log pre edm unity debug
在Unity中进行速度和GC Alloc的测试
测试脚本:
using UnityEngine; using System; using System.Collections; using System.Diagnostics; public class NullableTest : MonoBehaviour { void Start() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 1000000; i++) { int a = i; //int? a = i; a.GetHashCode(); } stopwatch.Stop(); UnityEngine.Debug.Log("time(ms): " + stopwatch.ElapsedMilliseconds); } }
100万次循环下,可空类型执行速度45ms,非可空类型执行速度12ms
关于GC很奇怪,始终都有32B的GC,不管被创建和调用多少次。
但值是恒定的,不会造成内存影响
标签:调用 top color watch log pre edm unity debug
原文地址:http://www.cnblogs.com/hont/p/6142786.html