Skip to content

Instantly share code, notes, and snippets.

@sangcu
Created May 17, 2020 12:25
Show Gist options
  • Save sangcu/c8c87e70a75a385c18aa63e64893d5db to your computer and use it in GitHub Desktop.
Save sangcu/c8c87e70a75a385c18aa63e64893d5db to your computer and use it in GitHub Desktop.
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