using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;
public class RefCls
{
public int a;
}
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int count = 1000000;
var s = new Stack<RefCls>(count);
var q = new Queue<RefCls>(count);
for (int i = 0; i < count; i++)
{
q.Enqueue(new RefCls());
s.Push(new RefCls());
}
Stopwatch stopwatch;
stopwatch = Stopwatch.StartNew();
for (int i = 0; i < count; i++)
{
var x = q.Dequeue();
q.Enqueue(x);
}
Debug.Log(stopwatch.ElapsedMilliseconds);
stopwatch = Stopwatch.StartNew();
for (int i = 0; i < count; i++)
{
var x = s.Pop();
s.Push(x);
}
Debug.Log(stopwatch.ElapsedMilliseconds);
}
// Update is called once per frame
}
https://github.com/gmhevinci/MotionFramework/blob/5a626d792256bf30b94fab605e5ebb56bd89fc09/Assets/MotionFramework/Scripts/Runtime/Engine/Engine.Reference/ReferenceCollector.cs#L14
这里的ds没必要用queue吧? 改成stack会不会好些? 还是说这里Queue有我忽略的含义?
疑惑cpucache会不会高一些.
以下是一个简单的测试代码. 速度有略微提升. 可以交换顺序. 测试一致