Last active
February 10, 2025 18:18
Revisions
-
davepcallan revised this gist
Feb 10, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public Config() SummaryStyle = SummaryStyle.Default .WithRatioStyle(RatioStyle.Trend) .WithTimeUnit(Perfolizer.Horology.TimeUnit.Nanosecond); } } -
davepcallan created this gist
Feb 10, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Reports; using System.Text; namespace Benchmarks; [MemoryDiagnoser] [HideColumns(Column.RatioSD, Column.AllocRatio, Column.Gen0, Column.Gen2)] [SimpleJob(RuntimeMoniker.Net90)] [ReturnValueValidator(failOnError: true)] // Validate methods are equivalent [Config(typeof(Config))] // Custom class to configure BenchmarkDotNet public class StringBuilderVPlus { private class Config : ManualConfig { public Config() { SummaryStyle = SummaryStyle.Default .WithRatioStyle(RatioStyle.Trend) .WithTimeUnit(Perfolizer.Horology.TimeUnit.Millisecond); } } [Params(10, 20)] // Run benchmarks with these parameters public int Concats; [Benchmark] public string StringBuilder() { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < Concats; i++) { stringBuilder.Append("Hello World"); } return stringBuilder.ToString(); } [Benchmark(Baseline = true)] public string StringConcatenation() { string str = ""; for (int i = 0; i < Concats; i++) { str += "Hello World"; } return str; } } public class Program { public static void Main(string[] args) { BenchmarkRunner.Run<StringBuilderVPlus>(); } }