// Use this for initialization void Start() { Dictionary <int, string> dic = new Dictionary <int, string>(); for (int i = 0; i < 1000; ++i) { dic.Add(i, string.Empty); } PerformanceChecker dicPerfChecker = new PerformanceChecker("foreach vs while", 1); dicPerfChecker.CheckAction("foreach", (i) => { foreach (var v in dic) { } }); dicPerfChecker.CheckAction("while", (i) => { var v = dic.GetEnumerator(); while (v.MoveNext()) { } }); dicPerfChecker.ShowResult(); }
// Use this for initialization void Start() { AimingData aimingData = new AimingData(LOOP_COUNT, 10); TestObj[] testObj = new TestObj[LOOP_COUNT]; for (int i = 0; i < testObj.Length; ++i) { testObj[i] = new TestObj(); } Vector3 target = new Vector3(100, 100, 100); PerformanceChecker sinPerfChecker = new PerformanceChecker("DOD vs OOP", 1); sinPerfChecker.CheckAction("DOD", (i) => { CalcAim(aimingData, target, LOOP_COUNT); }); sinPerfChecker.CheckAction("OOP", (i) => { for (int j = 0; j < LOOP_COUNT; ++j) { testObj[j].Aim(target); } }); sinPerfChecker.ShowResult(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Reset(); sw.Start(); CalcAim(aimingData, target, LOOP_COUNT); sw.Stop(); Debug.Log("dod : " + sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); for (int j = 0; j < LOOP_COUNT; ++j) { testObj[j].Aim(target); } sw.Stop(); Debug.Log("oop : " + sw.ElapsedMilliseconds); }
// Use this for initialization void Start() { State x = State.XXX; PerformanceChecker perfChecker = new PerformanceChecker("== vs Equals in Enum", 10000); perfChecker.CheckAction("==", (i) => { if (x == State.XXX) { } }); perfChecker.CheckAction("Equals", (i) => { if (x.Equals(State.XXX)) { } }); perfChecker.ShowResult(); }