How to add timestamp (date) to BenchmarkDotNet exported HTML or CSV file names?

1 day ago 2
ARTICLE AD BOX

There is an option for that (Config Options doc):

ConfigOptions.DontOverwriteResults - The exported result files should not be overwritten (by default they are overwritten).

So try adding:

WithOptions(ConfigOptions.DontOverwriteResults);

enter image description here

Alternatively you can use fileNameSuffix.

Some of the standard exporters already allow passing fileNameSuffix, for example - XML and Json one:

AddExporter(JsonExporter.Custom("_customFileNameSuffix", indentJson: true, excludeMeasurements: true));

For others the suffix property is not exposed but you can inherit it and override the suffix:

public class MyHtmlExporter : HtmlExporter { public MyHtmlExporter() { FileNameSuffix = $"_gurustron_{DateTime.UtcNow.Ticks}"; } protected override string FileNameSuffix { get; } } AddExporter(new MyHtmlExporter());

enter image description here

The same can be done with csv:

public class MyCsvExporter : CsvExporter { public MyCsvExporter() : base(CsvSeparator.CurrentCulture) // mimic the Default behavior { FileNameSuffix = $"_gurustron_{DateTime.UtcNow.Ticks}"; } protected override string FileNameSuffix { get; } }

One thing I noticed - not all suffixes actually work, for example DateTime.UtcNow.ToLongTimeString() (instead of DateTime.UtcNow.Ticks) has not worked for me.

Read Entire Article