/// <summary> /// Initializes the job. The time taken here is measured. /// </summary> /// <param name="options">The benchmark options</param> public override void Initialize(BenchmarkOptions options) { if (options.Incremental) { incrementalValue = Observable.Expression(Query(Benchmark.Root)); } }
/// <summary> /// Informs the user that used wrong arguments /// </summary> /// <param name="options">The benchmark options to be used</param> protected virtual void PrintWrongArgumentsHelp(BenchmarkOptions options) { PrintErrorLog("You are using me wrongly."); Log.WriteLine("The correct usage is as follows:"); var helpText = CommandLine.Text.HelpText.AutoBuild(options); Log.WriteLine(helpText.RenderParsingErrorsText(options, 4)); }
/// <summary> /// Runs the benchmark at the given run index /// </summary> /// <param name="options">The benchmark options to be used</param> /// <param name="i">Run index</param> private void RunBenchmark(int i, BenchmarkOptions options) { RunIndex = i; Phase = "Load"; stopwatch.Start(); LoadRoot(options); stopwatch.Stop(); Report(null, "Time", stopwatch.Elapsed.TotalMilliseconds, options); foreach (var job in Analyzers) { Phase = "Initialize"; job.Prepare(options); stopwatch.Restart(); job.Initialize(options); stopwatch.Stop(); Report(job.Name, "Time", stopwatch.Elapsed.TotalMilliseconds, options); if (i == 0 && options.Memory) { Report(job.Name, "Memory", job.GetMemoryConsumption(), options); } Phase = "Validate"; stopwatch.Restart(); job.AnalyzeAndReport(options); stopwatch.Stop(); Report(job.Name, "Time", stopwatch.Elapsed.TotalMilliseconds, options); } if (Modifier != null) { for (int j = 0; j < options.Iterations; j++) { Iteration = j; Phase = "Modify"; stopwatch.Restart(); Modifier(j); stopwatch.Stop(); Report(null, "Time", stopwatch.Elapsed.TotalMilliseconds, options); foreach (var job in Analyzers) { Phase = "Revalidate"; stopwatch.Restart(); var reportAction = job.AnalyzeAndReport(options); stopwatch.Stop(); reportAction(); Report(job.Name, "Time", stopwatch.Elapsed.TotalMilliseconds, options); } } } }
/// <summary> /// Initializes the job. The time taken here is measured. /// </summary> /// <param name="options">The benchmark options</param> public override void Initialize(BenchmarkOptions options) { if (options.Incremental) { currentPattern = Pattern(Benchmark.Root).AsNotifiable(); } else { currentPattern = Pattern(Benchmark.Root); } }
/// <summary> /// Analyzes the data and returns a reporting action /// </summary> /// <param name="options">The benchmark options</param> /// <returns>An action that will write the data to the reports. This is then no longer measured</returns> public override Action AnalyzeAndReport(BenchmarkOptions options) { TObject obj; if (incrementalValue != null) { obj = incrementalValue.Value; } else { obj = functionCompiled(); } return(() => Benchmark.Report(Name, "Value", obj, options)); }
/// <summary> /// Runs the benchmark with the given command line arguments /// </summary> /// <param name="args">The commandline arguments</param> public void Run(string[] args) { var options = new BenchmarkOptions(); if (!CommandLine.Parser.Default.ParseArguments(args, options)) { PrintGreeting(); PrintWrongArgumentsHelp(options); Environment.Exit(1); return; } Run(options); }
/// <summary> /// Runs the benchmark with the given command line arguments /// </summary> /// <param name="options">The benchmark options</param> public void Run(BenchmarkOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (options.LogFile != null) { Log = File.AppendText(options.LogFile); } if (options.Target != null) { Reporting = File.AppendText(options.Target); } PrintGreeting(); if (!CheckAnalyzers(options)) { Environment.Exit(2); return; } for (int i = 0; i < options.Runs; i++) { RunBenchmark(i, options); } if (Log != null) { Log.Close(); } if (Reporting != null) { Reporting.Close(); } }
/// <summary> /// Remove analyzers that are not wanted in the current run /// </summary> /// <param name="options">The benchmark options to be used</param> /// <returns>False if there are analyzers wanted that do not exist</returns> private bool CheckAnalyzers(BenchmarkOptions options) { if (options.Analyzers != null && options.Analyzers.Count > 0) { for (int i = Analyzers.Count - 1; i >= 0; i--) { if (!options.Analyzers.Contains(Analyzers[i].Name)) { Analyzers.RemoveAt(i); } else { options.Analyzers.Remove(Analyzers[i].Name); } } if (options.Analyzers.Count > 0) { PrintWrongAnalyzersHelp(options); return(false); } } return(true); }
/// <summary> /// Loads the root model element /// </summary> /// <param name="options">The benchmark options to be used</param> protected virtual void LoadRoot(BenchmarkOptions options) { Root = Repository.Resolve(options.ModelPath).RootElements.OfType <TRoot>().Single(); }
/// <summary> /// Initializes the job. The time taken here is measured. /// </summary> /// <param name="options">The benchmark options</param> public abstract void Initialize(BenchmarkOptions options);
/// <summary> /// Creates an entry in the reporting CSV /// </summary> /// <param name="job">The job that reports or Null if this reports is not related to a job</param> /// <param name="phase">The action that has been done or the phase that the job is in</param> /// <param name="metricName">The metric that is to be measured</param> /// <param name="value">The value to report</param> /// <param name="options">The benchmark options to be used</param> protected virtual void Report(string job, string phase, string metricName, object value, BenchmarkOptions options) { Reporting.WriteLine("{0};{1};{2};{3};{4};{5};{6};", options.Id, job, phase, RunIndex, Iteration, metricName, value); }
/// <summary> /// Creates an entry in the reporting CSV /// </summary> /// <param name="job">The job that reports or Null if this reports is not related to a job</param> /// <param name="phase">The action that has been done or the phase that the job is in</param> /// <param name="metricName">The metric that is to be measured</param> /// <param name="value">The value to report</param> /// <param name="options">The benchmark options to be used</param> public void Report(string job, string metricName, object value, BenchmarkOptions options) { Report(job, Phase, metricName, value, options); }
/// <summary> /// Analyzes the data and returns a reporting action /// </summary> /// <param name="options">The benchmark options</param> /// <returns>An action that will write the data to the reports. This is then no longer measured</returns> public abstract Action AnalyzeAndReport(BenchmarkOptions options);
/// <summary> /// Prints a message that some analyzers have been selected that do not exist /// </summary> /// <param name="options">The benchmark options to be used</param> protected virtual void PrintWrongAnalyzersHelp(BenchmarkOptions options) { PrintErrorLog(string.Format("The analyzers {0} could not be found.", string.Join(", ", options.Analyzers))); }
/// <summary> /// Analyzes the data and returns a reporting action /// </summary> /// <param name="options">The benchmark options</param> /// <returns>An action that will write the data to the reports. This is then no longer measured</returns> public override Action AnalyzeAndReport(BenchmarkOptions options) { var count = currentPattern.Count(); return(() => Benchmark.Report(Name, "Count", count, options)); }
/// <summary> /// Prepares the job before initialization. The time taken here is not measured /// </summary> /// <param name="options">The benchmark options</param> public override void Prepare(BenchmarkOptions options) { functionCompiled = Query(Benchmark.Root).Compile(); }
/// <summary> /// Prepares the job before initialization. The time taken here is not measured /// </summary> /// <param name="options">The benchmark options</param> public virtual void Prepare(BenchmarkOptions options) { }