gmhevinci/MotionFramework

ReferenceCollector内部的数据结构改成Stack?

lexnewgate opened this issue · 1 comments

这里的ds没必要用queue吧?
改成stack会不会好些? 还是说这里Queue有我忽略的含义?

疑惑cpucache会不会高一些.

以下是一个简单的测试代码. 速度有略微提升. 可以交换顺序. 测试一致

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
}

谢谢你的提议,已经采纳