From 78dc260c5026cdd25d754392fd9a48229ad05386 Mon Sep 17 00:00:00 2001 From: nietras Date: Wed, 3 Jan 2024 14:41:54 +0100 Subject: [PATCH] Add bench.ps1 and customize run and exporters (#63) * Add bench.ps1 and customize run and exporters * remove filter from bench.ps1 --- .../Benchmarks/PackageAssetsSuite.cs | 3 +- NCsvPerf/Program.cs | 29 ++++++++++++++++--- bench.ps1 | 3 ++ 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 bench.ps1 diff --git a/NCsvPerf/CsvReadable/Benchmarks/PackageAssetsSuite.cs b/NCsvPerf/CsvReadable/Benchmarks/PackageAssetsSuite.cs index 17b3962..166c5fb 100644 --- a/NCsvPerf/CsvReadable/Benchmarks/PackageAssetsSuite.cs +++ b/NCsvPerf/CsvReadable/Benchmarks/PackageAssetsSuite.cs @@ -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; diff --git a/NCsvPerf/Program.cs b/NCsvPerf/Program.cs index 6c2b620..52c15d4 100644 --- a/NCsvPerf/Program.cs +++ b/NCsvPerf/Program.cs @@ -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; @@ -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(config, args); } diff --git a/bench.ps1 b/bench.ps1 new file mode 100644 index 0000000..52c1c1a --- /dev/null +++ b/bench.ps1 @@ -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