protected static Timings Time(HybridAction action, decimal modifier, int iterations = 100) { var watch = new Stopwatch(); // warmup action(out var stats); var timings = new Timings { DbTime = 0, CodeTime = 0 }; for (var i = 0; i < iterations; i++) { watch.Restart(); action(out stats); timings.DbTime += stats.QueryDurationInMilliseconds; timings.CodeTime += watch.ElapsedMilliseconds - stats.QueryDurationInMilliseconds; } timings.DbTime = (long)(timings.DbTime / modifier); timings.CodeTime = (long)(timings.CodeTime / modifier); Console.WriteLine($"Total db time over {iterations} iterations was {timings.DbTime}."); Console.WriteLine($"Total code time over {iterations} iterations was {timings.CodeTime}."); return(timings); }
protected static Timings Time(HybridAction action, decimal modifier, int iterations = 100) { var watch = new Stopwatch(); QueryStats stats; // warmup action(out stats); var timings = new Timings { DbTimeLowest = long.MaxValue, CodeTimeLowest = long.MaxValue }; for (var i = 0; i < iterations; i++) { watch.Restart(); action(out stats); timings.DbTimeLowest = Math.Min( timings.DbTimeLowest, stats.QueryDurationInMilliseconds); timings.CodeTimeLowest = Math.Min( timings.CodeTimeLowest, watch.ElapsedMilliseconds - stats.QueryDurationInMilliseconds); } timings.DbTimeLowest = (long)(timings.DbTimeLowest / modifier); timings.CodeTimeLowest = (long)(timings.CodeTimeLowest / modifier); Console.WriteLine("Lowest db time was " + timings.DbTimeLowest); Console.WriteLine("Lowest code time was " + timings.CodeTimeLowest); return(timings); }
protected Timings Time(HybridAction action, int iterations = 100) => Time(action, systemModifier, iterations);
protected Timings Time(HybridAction action, int iterations = 100) { return(Time(action, systemModifier, iterations)); }