private void WarmUp(IOrmExecuter executer) { Stopwatch stopwatch = Stopwatch.StartNew(); executer.GetItemAsObject(1); executer.GetItemAsDynamic(1); stopwatch.Stop(); ResultsWarmUp.Add(CreateResult(executer, GetNanoSeconds(stopwatch), "WarmUp")); }
public void Run(bool warmUp = false) { PrepareDatabase(); Results.Clear(); ResultsForDynamicItem.Clear(); ResultsForAllItems.Clear(); ResultsForAllDynamicItems.Clear(); ResultsWarmUp.Clear(); var rand = new Random(); foreach (IOrmExecuter executer in Executers.OrderBy(ignore => rand.Next())) { Console.WriteLine("\texecut {0}", executer.Name); executer.Init(ConnectionString); // Warm-up if (warmUp) { Stopwatch watchForWaemUp = new Stopwatch(); watchForWaemUp.Start(); executer.GetItemAsObject(IterationCount + 1); executer.GetItemAsDynamic(IterationCount + 1); watchForWaemUp.Stop(); ResultsWarmUp.Add(new BenchmarkResult { Name = executer.Name, ExecTime = watchForWaemUp.ElapsedMilliseconds }); } // Object Stopwatch watch = new Stopwatch(); long firstItemExecTime = 0; for (int i = 1; i <= IterationCount; i++) { watch.Start(); var obj = executer.GetItemAsObject(i); Debug.Assert(obj.Id == i, "obj.Id == i"); watch.Stop(); //if (obj?.Id != i) // throw new ApplicationException("Invalid object returned."); if (i == 1) { firstItemExecTime = watch.ElapsedMilliseconds; } } Results.Add(new BenchmarkResult { Name = executer.Name, ExecTime = watch.ElapsedMilliseconds, FirstItemExecTime = firstItemExecTime }); // Dynamic Stopwatch watchForDynamic = new Stopwatch(); firstItemExecTime = 0; for (int i = 1; i <= IterationCount; i++) { watchForDynamic.Start(); var dynamicObj = executer.GetItemAsDynamic(i); //bool checkResult = dynamicObj.Id == i; //Debug.Assert(dynamicObj!=null,"dynamicObj!=null"); //Debug.Assert(checkResult,"dynamicObj.Id == i"); watchForDynamic.Stop(); //if (dynamicObj?.Id != i) // throw new ApplicationException("Invalid object returned."); if (i == 1) { firstItemExecTime = watchForDynamic.ElapsedMilliseconds; } } ResultsForDynamicItem.Add(new BenchmarkResult { Name = executer.Name, ExecTime = watchForDynamic.ElapsedMilliseconds, FirstItemExecTime = firstItemExecTime }); // All Objects Stopwatch watchForAllItems = new Stopwatch(); watchForAllItems.Start(); var elements = executer.GetAllItemsAsObject(); Debug.Assert(elements.Count > 5000); watchForAllItems.Stop(); ResultsForAllItems.Add(new BenchmarkResult { Name = executer.Name, ExecTime = watchForAllItems.ElapsedMilliseconds }); // All Dynamics Stopwatch watchForAllDynamicItems = new Stopwatch(); watchForAllDynamicItems.Start(); executer.GetAllItemsAsDynamic(); watchForAllDynamicItems.Stop(); ResultsForAllDynamicItems.Add(new BenchmarkResult { Name = executer.Name, ExecTime = watchForAllDynamicItems.ElapsedMilliseconds }); executer.Finish(); GC.Collect(); } }