List.Add、LinkedList.Add、HashSet.Add、Dictionary.Addの速度比較をしたので結果を残しておきます。
[ 環境 ]
Unity 2018.4.14.f1
[ 比較結果 ]
List.Add | 0 ms |
LinkedList.Add | 23 ms |
HashSet.Add | 2 ms |
Dictionary.Add | 6 ms |
[ スクリプト ]
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PerformanceComparison : MonoBehaviour { void Start() { System.Diagnostics.Stopwatch StopWatch = new System.Diagnostics.Stopwatch(); int Count = 100000; List<int> List_ = new List<int>(){}; LinkedList<int> LinkedList_ = new LinkedList<int>(){}; HashSet<int> HashSet_ = new HashSet<int>(){}; Dictionary<int, int> Dictionary_ = new Dictionary<int, int>(){}; //List StopWatch.Restart(); for(int i = 0; i < Count; i++) { List_.Add(i); } Debug.Log(StopWatch.ElapsedMilliseconds); //LinkedList StopWatch.Restart(); for(int i = 0; i < Count; i++) { LinkedList_.AddLast(i); } Debug.Log(StopWatch.ElapsedMilliseconds); //HashSet StopWatch.Restart(); for(int i = 0; i < Count; i++) { HashSet_.Add(i); } Debug.Log(StopWatch.ElapsedMilliseconds); //Dictionary StopWatch.Restart(); for(int i = 0; i < Count; i++) { Dictionary_.Add(i, i); } Debug.Log(StopWatch.ElapsedMilliseconds); } }