-
-
Notifications
You must be signed in to change notification settings - Fork 986
/
Copy pathIntroSmokeStringBuilder.cs
34 lines (31 loc) · 1.16 KB
/
IntroSmokeStringBuilder.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
using BenchmarkDotNet.Attributes;
using System.Text;
namespace BenchmarkDotNet.Samples
{
[MemoryDiagnoser(false)]
public class IntroSmokeStringBuilder
{
[Benchmark]
[Arguments(1)]
[Arguments(1_000)]
public StringBuilder Append_Strings(int repeat)
{
StringBuilder builder = new StringBuilder();
// strings are not sorted by length to mimic real input
for (int i = 0; i < repeat; i++)
{
builder.Append("12345");
builder.Append("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN");
builder.Append("1234567890abcdefghijklmnopqrstuvwxy");
builder.Append("1234567890");
builder.Append("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHI");
builder.Append("1234567890abcde");
builder.Append("1234567890abcdefghijklmnopqrstuvwxyzABCD");
builder.Append("1234567890abcdefghijklmnopqrst");
builder.Append("1234567890abcdefghij");
builder.Append("1234567890abcdefghijklmno");
}
return builder;
}
}
}