Created
May 17, 2020 12:25
-
-
Save sangcu/c8c87e70a75a385c18aa63e64893d5db 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
using System.Collections.Generic; | |
using System.Text; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace TestHub | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var summary = BenchmarkRunner.Run(typeof(Program).Assembly); | |
} | |
} | |
public class StringTest | |
{ | |
private object[] Items; | |
private string formatTemplate = string.Empty; | |
public StringTest() | |
{ | |
var count = 0; | |
var builder = new StringBuilder(); | |
var arrs= new List<object>(); | |
do | |
{ | |
builder.Append($"{count}"); | |
arrs.Add(new object()); | |
count++; | |
} while (count < 5000); | |
formatTemplate = builder.ToString(); | |
Items = arrs.ToArray(); | |
} | |
[Benchmark] | |
public string Concat() | |
{ | |
return string.Concat(Items); | |
} | |
[Benchmark] | |
public string Format() | |
{ | |
return string.Format(formatTemplate, Items); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment