protected void AddResult(PerformanceEntry entry) { this.entries.Add(entry); if (options.Enabled) { this.summaryTable.DrawRow($"t-{entries.Count}", this.options.TimeFormatter.Format(entries[entries.Count - 1].Elapsed), entry.HasError ? "*" : String.Empty); } }
/// <summary> /// Measures the specified action logging its PerformanceEntry. /// </summary> /// <param name="action">The action.</param> /// <returns></returns> public PerformanceEntry Measure(Func <PerformanceEntry> action) { //start drawing the table header if it's the first measure if (this.entries.Count == 0 && options.Enabled) { this.summaryTable.Start(); } PerformanceEntry entry = action(); this.AddResult(entry); return(entry); }
/// <summary> /// Dumps the summary of the performance entries on console. /// </summary> private void DumpResultsAndEnd() { if (!options.Enabled) { return; } if (this.options.ShowResponses) { this.writer.WriteLine(); this.writer.WriteLine("RESPONSES".Center(80, '*')); for (int index = 0; index < entries.Count; index++) { PerformanceEntry entry = entries[index]; this.writer.WriteLine($"t-{index}: { entry.Result}"); } this.writer.DrawLine('*'); this.writer.WriteLine(); } this.writer.DrawLine('='); this.writer.WriteLine(); }