Skip to content

Commit 30cc6a9

Browse files
committed
Added ValueType append benchmark
1 parent db796aa commit 30cc6a9

File tree

3 files changed

+76
-32
lines changed

3 files changed

+76
-32
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace LinkDotNet.StringBuilder.Benchmarks;
4+
5+
[MemoryDiagnoser]
6+
public class AppendBenchmarks
7+
{
8+
[Benchmark]
9+
public string DotNetStringBuilder()
10+
{
11+
var builder = new System.Text.StringBuilder();
12+
builder.AppendLine("That is the first line of our benchmark.");
13+
builder.AppendLine("We can multiple stuff in here if want.");
14+
builder.AppendLine("The idea is that we can resize the internal structure from time to time.");
15+
builder.AppendLine("We can also add other Append method if we want. But we keep it easy for now.");
16+
return builder.ToString();
17+
}
18+
19+
[Benchmark]
20+
public string ValueStringBuilder()
21+
{
22+
var builder = new ValueStringBuilder();
23+
builder.AppendLine("That is the first line of our benchmark.");
24+
builder.AppendLine("We can multiple stuff in here if want.");
25+
builder.AppendLine("We can multiple stuff in here if want.");
26+
builder.AppendLine("The idea is that we can resize the internal structure from time to time.");
27+
builder.AppendLine("We can also add other Append method if we want. But we keep it easy for now.");
28+
return builder.ToString();
29+
}
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace LinkDotNet.StringBuilder.Benchmarks;
4+
5+
[MemoryDiagnoser]
6+
public class AppendValueTypes
7+
{
8+
[Benchmark]
9+
public string DotNetStringBuilder()
10+
{
11+
var builder = new System.Text.StringBuilder();
12+
13+
for (var i = 0; i < 25; i++)
14+
{
15+
builder.Append(true);
16+
builder.Append(int.MaxValue);
17+
builder.Append(decimal.MaxValue);
18+
builder.Append(byte.MinValue);
19+
builder.Append(float.Epsilon);
20+
builder.Append(double.Epsilon);
21+
}
22+
23+
return builder.ToString();
24+
}
25+
26+
[Benchmark]
27+
public string ValueStringBuilder()
28+
{
29+
var builder = new ValueStringBuilder();
30+
31+
for (var i = 0; i < 25; i++)
32+
{
33+
builder.Append(true);
34+
builder.Append(int.MaxValue);
35+
builder.Append(decimal.MaxValue);
36+
builder.Append(byte.MinValue);
37+
builder.Append(float.Epsilon);
38+
builder.Append(double.Epsilon);
39+
}
40+
41+
return builder.ToString();
42+
}
43+
}
Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
1-
using System.Text;
2-
using BenchmarkDotNet.Attributes;
3-
using BenchmarkDotNet.Running;
4-
using LinkDotNet.StringBuilder;
1+
using BenchmarkDotNet.Running;
2+
using LinkDotNet.StringBuilder.Benchmarks;
53

6-
BenchmarkSwitcher.FromAssembly(typeof(Benchmarks).Assembly).Run();
7-
8-
[MemoryDiagnoser]
9-
public class Benchmarks
10-
{
11-
[Benchmark]
12-
public string DotNetStringBuilder()
13-
{
14-
var builder = new StringBuilder();
15-
builder.AppendLine("That is the first line of our benchmark.");
16-
builder.AppendLine("We can multiple stuff in here if want.");
17-
builder.AppendLine("The idea is that we can resize the internal structure from time to time.");
18-
builder.AppendLine("We can also add other Append method if we want. But we keep it easy for now.");
19-
return builder.ToString();
20-
}
21-
22-
[Benchmark]
23-
public string ValueStringBuilder()
24-
{
25-
var builder = new ValueStringBuilder();
26-
builder.AppendLine("That is the first line of our benchmark.");
27-
builder.AppendLine("We can multiple stuff in here if want.");
28-
builder.AppendLine("We can multiple stuff in here if want.");
29-
builder.AppendLine("The idea is that we can resize the internal structure from time to time.");
30-
builder.AppendLine("We can also add other Append method if we want. But we keep it easy for now.");
31-
return builder.ToString();
32-
}
33-
}
4+
BenchmarkSwitcher.FromAssembly(typeof(AppendBenchmarks).Assembly).Run();

0 commit comments

Comments
 (0)