private void LoadItemsAsync() { CultureInfo culture = Settings.DatabaseCulture; // get a processId so we can stop it if the user request a new batch before we finished this one int processId = ++_loadProcessId; SetCollectionView(null); Observable.Start(() => { // load items from database using (var provider = new MangosProvider()) using (var pc = new PerformanceChecker("GetItems")) { return(provider.GetItems(culture) .Select(o => new LocalizedItem(o)) .ToList()); } }) .ObserveOnDispatcher() .Subscribe(result => { // check processId to make sure the user has not requested another batch meantime if (processId != _loadProcessId) { return; } // display loaded items to user SetCollectionView(result); }, OnError); }
// 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(); }
static void Main(string[] args) { PerformanceChecker checker = new PerformanceChecker(Method1, Method2); checker.CountOfPerform = 1_000_000; var elapsedTimes = checker.Perform(); foreach (double elapsedTime in elapsedTimes) { Console.WriteLine(elapsedTime); } // 1.160833 // 1.874759 Console.WriteLine(checker.PerformResult()); // ================================ // Method1 : 1.160833sec // Method2 : 1.874759sec // ================================ }
private void LoadItemsAsync() { CultureInfo culture = Settings.DatabaseCulture; // get a processId so we can stop it if the user request a new batch before we finished this one int processId = ++_loadProcessId; SetCollectionView(null); Observable.Start(() => { // load items from database using (var provider = new MangosProvider()) using (var pc = new PerformanceChecker("GetItems")) { return provider.GetItems(culture) .Select(o => new LocalizedItem(o)) .ToList(); } }) .ObserveOnDispatcher() .Subscribe(result => { // check processId to make sure the user has not requested another batch meantime if (processId != _loadProcessId) return; // display loaded items to user SetCollectionView(result); }, OnError); }