private static void TimedDelegateDecompiler(int NumTimes, AdventureWorksLt2012 db, int NumTakes) { using (var timer = new TimerToConsole("With DelegateDecompiler", NumTimes)) for (int i = 0; i < NumTimes; i++) { var item1 = db.Customers.Select(x => x.FullName).Take(NumTakes).Decompile().ToList(); } }
private static void TimedNormalAccess(int NumTimes, AdventureWorksLt2012 db, int NumTakes) { using (var timer = new TimerToConsole("Normal access", NumTimes)) for (int i = 0; i < NumTimes; i++) { var item1 = db.Customers.Select(c => c.Title + " " + c.FirstName + " " + c.LastName + " " + c.Suffix) .Take(NumTakes) .ToList(); } }
private static void TimedCheckIfItNeedsDecompile(int NumTimes, AdventureWorksLt2012 db, int NumTakes, bool okToUseDecompileIfNeeded) { using (var timer = new TimerToConsole("Normal access, but checks if needed. Decompile " + (okToUseDecompileIfNeeded ? "was added" : "was NOT added"), NumTimes)) { var addDecompile = typeof(Customer).GetCustomAttribute <ComputedAttribute>() != null && okToUseDecompileIfNeeded; for (int i = 0; i < NumTimes; i++) { var expression = db.Customers.Select( c => c.Title + " " + c.FirstName + " " + c.LastName + " " + c.Suffix) .Take(NumTakes); var item1 = addDecompile ? expression.Decompile().ToList() : expression.ToList(); } } }