Last active
May 25, 2021 19:48
-
-
Save JerryNixon/e8685a08930172a0e2b245a7156adfd8 to your computer and use it in GitHub Desktop.
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 characters
public class Program | |
{ | |
static void Main() | |
{ | |
BenchmarkRunner.Run<Harness>(); | |
} | |
} | |
public class Harness | |
{ | |
private static readonly string a = "1d76e414-21b4-49f8-855d-6c0bb76aa210"; | |
private static readonly string b = "6e38457f-4d8c-4056-8a64-a42fcd78127a"; | |
private static readonly string c = "8a8a6c5c-dee6-4407-b146-fb870736b860"; | |
private static readonly string d = "e391da11-c962-42f0-ab48-5c7fe8001abd"; | |
private static readonly string e = "040a44d4-fb1f-43d2-8bbc-4b6de42405b3"; | |
[Benchmark(Baseline = true)] | |
public string Plus() => a + b + c + d + e; | |
[Benchmark] | |
public string Concat() => string.Concat(a, b, c, d, e); | |
[Benchmark] | |
public string Interpolate() => $"{a}{b}{c}{d}{e}"; | |
[Benchmark] | |
public string InterpolatePlus() => $"{$"{a}{b}{c}"}{d}{e}"; | |
[Benchmark] | |
public string InterpolatePlus2() | |
{ | |
var x = $"{a}{b}{c}"; | |
return $"{x}{d}{e}"; | |
} | |
[Benchmark] | |
public string StringBuilder() | |
{ | |
var sb = new StringBuilder(); | |
sb.Append(new[] { a, b, c, d, e }); | |
return sb.ToString(); | |
} | |
} |
Author
JerryNixon
commented
May 25, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment