Skip to content

Commit

Permalink
Add bench.ps1 and customize run and exporters (#63)
Browse files Browse the repository at this point in the history
* Add bench.ps1 and customize run and exporters

* remove filter from bench.ps1
  • Loading branch information
nietras authored Jan 3, 2024
1 parent ac02816 commit 78dc260
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion NCsvPerf/CsvReadable/Benchmarks/PackageAssetsSuite.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using System.IO;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;

namespace Knapcode.NCsvPerf.CsvReadable.TestCases
{
[MemoryDiagnoser]
[SimpleJob(1, 2, 6, 1)]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class PackageAssetsSuite
{
private byte[] _bytes;
Expand Down
29 changes: 25 additions & 4 deletions NCsvPerf/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using Knapcode.NCsvPerf.CsvReadable.TestCases;

Expand All @@ -8,11 +13,27 @@ public class Program
{
private static void Main(string[] args)
{
IConfig config = null;
#if DEBUG
config = new DebugInProcessConfig();
var config = new DebugInProcessConfig();
#else
config = null;
// Remove time units from column values for csv exporter as per:
// https://github.com/dotnet/BenchmarkDotNet/issues/1207
var csvExporter = new CsvExporter(
CsvSeparator.CurrentCulture,
new SummaryStyle(
cultureInfo: System.Globalization.CultureInfo.InvariantCulture,
printUnitsInHeader: true,
printUnitsInContent: false,
timeUnit: Perfolizer.Horology.TimeUnit.Millisecond,
sizeUnit: SizeUnit.KB
));
var config = ManualConfig
.CreateEmpty()
.AddColumnProvider(DefaultColumnProviders.Instance)
.AddLogger(ConsoleLogger.Default)
.AddExporter(csvExporter)
.AddExporter(HtmlExporter.Default)
.AddExporter(MarkdownExporter.GitHub);
#endif
BenchmarkRunner.Run<PackageAssetsSuite>(config, args);
}
Expand Down
3 changes: 3 additions & 0 deletions bench.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env pwsh
# Add `--filter *.METHOD*` or similar to run subset of benchmarks
dotnet run -c Release --project NCsvPerf\NCsvPerf.csproj -- -m --minWarmupCount 3 --maxWarmupCount 5 --minIterationCount 5 --maxIterationCount 11

0 comments on commit 78dc260

Please sign in to comment.