赞
踩
using System.Collections; using System.Collections.Generic; using UnityEngine; using UGFramework; using UnityEngine.Events; using System.Diagnostics; namespace GamePlay { public class NewBehaviourScript : MonoBehaviour { public WeaponPropertySObj weaponP; public int damage = 30; public int damage1 = 0; public int damage2 = 0; public int TIMES = 100000000; void Start() { Normal(); SO(); } public void ExcuteTime(UnityAction method) { Stopwatch sw = new Stopwatch(); sw.Start(); method(); sw.Stop(); UnityEngine.Debug.Log(string.Format("测试方法总共耗时: {0} ms(毫秒)", sw.ElapsedMilliseconds)); } private void Normal() { print("普通赋值"); ToolKit.ExcuteTime(() => { for (int i = 0; i < TIMES; i++) { damage1 = damage; } }); } private void SO() { print("so赋值"); ToolKit.ExcuteTime(() => { for (int i = 0; i < TIMES; i++) { damage2 = weaponP.damage; } }); } } }
经过多次对结果进行对比,如下图:
从结果可以看到两种方式的执行效率都差不多。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。