Created
August 21, 2024 13:52
-
-
Save danielmarbach/e2d194f4bff3df4a7170d7c49c7f76a2 to your computer and use it in GitHub Desktop.
This file contains 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 characters
using System.Text; | |
using BenchmarkDotNet.Attributes; | |
namespace MicroBenchmarks.Strings; | |
[SimpleJob] | |
[MemoryDiagnoser] | |
public class StringBuilderAppend | |
{ | |
[Benchmark(Baseline = true)] | |
public string AppendFormat() | |
{ | |
var stringBuilder = new StringBuilder(); | |
stringBuilder.AppendFormat("Line {0}\n", 42); | |
return stringBuilder.ToString(); | |
} | |
[Benchmark] | |
public string Append() | |
{ | |
var stringBuilder = new StringBuilder(); | |
stringBuilder.Append($"Line {42}\n"); | |
return stringBuilder.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment