-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathProgram.cs
44 lines (35 loc) · 979 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<StringBuilderBenchmark>();
[MemoryDiagnoser]
public class StringBuilderBenchmark
{
private const string TextToAppend = "Hello World from Steven";
[Params(5, 10, 25)]
public int Iterations { get; set; }
[Benchmark]
public string StringBuilder()
{
var builder = new StringBuilder();
for (var i = 0; i < Iterations; i++)
builder.Append(TextToAppend);
return builder.ToString();
}
[Benchmark]
public string ListOfStrings()
{
var list = new List<string>();
for(var i = 0; i< Iterations;i++)
list.Add(TextToAppend);
return string.Join(string.Empty, list);
}
[Benchmark]
public string Concat()
{
var output = string.Empty;
for (var i = 0; i < Iterations; i++)
output += TextToAppend;
return output;
}
}