/// <summary> /// Adds file output to the benchmark. /// </summary> /// <remarks> /// Multiple file outputs can be added. /// /// filename must be supplied when namingConvention == FixedName. /// customFilenameFunc must be supplied when namingConvention == Custom. /// </remarks> /// <param name="folder">Folder to store benchmarks.</param> /// <param name="fileMode">Whether data should be appended or overwritten.</param> /// <param name="namingConvention">Naming convention of output files.</param> /// <param name="filename">Name of the file. </param> /// <param name="customFilenameFunc">Function that returns the name for an output file.</param> public void AddFileOutput(string folder = "Benchmarks/", FileMode fileMode = FileMode.Append, NamingConvention namingConvention = NamingConvention.Timestamp, string filename = null, Func <string> customFilenameFunc = null) { Func <string> filenameFunc; switch (namingConvention) { case NamingConvention.Timestamp: filenameFunc = () => $"{new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()}.txt"; break; case NamingConvention.FixedName: if (string.IsNullOrEmpty(filename)) { throw new ArgumentException("Filename must not be null or empty when using FixedName naming convention."); } filenameFunc = () => filename; break; case NamingConvention.Custom: if (customFilenameFunc == null) { throw new ArgumentException("Custom filename function must not be null when using Custom naming convention."); } filenameFunc = customFilenameFunc; break; default: throw new ArgumentOutOfRangeException(); } var fileOutput = new FileOutput(folder, fileMode, filenameFunc); FileOutputs.Add(fileOutput); }
public FileOutput(string folder, FileMode fileMode, Func <string> filenameFunc) { Folder = folder; FileMode = fileMode; FilenameFunc = filenameFunc; }