-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDiagnosticsFormattingBenchmarks.cs
More file actions
111 lines (93 loc) · 3.03 KB
/
DiagnosticsFormattingBenchmarks.cs
File metadata and controls
111 lines (93 loc) · 3.03 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using BenchmarkDotNet.Attributes;
using System;
using System.Globalization;
namespace FixedMathSharp.Benchmarks;
[MemoryDiagnoser]
public class DiagnosticsFormattingBenchmarks
{
private readonly Fixed64[] _scalars = BenchmarkFixtures.ScalarsA;
private readonly Vector3d[] _vectors = BenchmarkFixtures.VectorsA;
private readonly FixedQuaternion[] _quaternions = BenchmarkFixtures.RotationsA;
private readonly Fixed4x4[] _matrices = BenchmarkFixtures.Matrices;
private readonly char[] _buffer = new char[512];
[Benchmark]
public int Fixed64ToString()
{
int length = 0;
for (int i = 0; i < _scalars.Length; i++)
length += _scalars[i].ToString("0.00", CultureInfo.InvariantCulture).Length;
return length;
}
[Benchmark]
public int Fixed64TryFormat()
{
int length = 0;
Span<char> destination = _buffer.AsSpan();
for (int i = 0; i < _scalars.Length; i++)
{
if (_scalars[i].TryFormat(destination, out int charsWritten, "0.00", CultureInfo.InvariantCulture))
length += charsWritten;
}
return length;
}
[Benchmark]
public int Vector3dToString()
{
int length = 0;
for (int i = 0; i < _vectors.Length; i++)
length += _vectors[i].ToString("0.00", CultureInfo.InvariantCulture).Length;
return length;
}
[Benchmark]
public int Vector3dTryFormat()
{
int length = 0;
Span<char> destination = _buffer.AsSpan();
for (int i = 0; i < _vectors.Length; i++)
{
if (_vectors[i].TryFormat(destination, out int charsWritten, "0.00", CultureInfo.InvariantCulture))
length += charsWritten;
}
return length;
}
[Benchmark]
public int FixedQuaternionToString()
{
int length = 0;
for (int i = 0; i < _quaternions.Length; i++)
length += _quaternions[i].ToString("0.00", CultureInfo.InvariantCulture).Length;
return length;
}
[Benchmark]
public int FixedQuaternionTryFormat()
{
int length = 0;
Span<char> destination = _buffer.AsSpan();
for (int i = 0; i < _quaternions.Length; i++)
{
if (_quaternions[i].TryFormat(destination, out int charsWritten, "0.00", CultureInfo.InvariantCulture))
length += charsWritten;
}
return length;
}
[Benchmark]
public int Fixed4x4ToString()
{
int length = 0;
for (int i = 0; i < _matrices.Length; i++)
length += _matrices[i].ToString("0.00", CultureInfo.InvariantCulture).Length;
return length;
}
[Benchmark]
public int Fixed4x4TryFormat()
{
int length = 0;
Span<char> destination = _buffer.AsSpan();
for (int i = 0; i < _matrices.Length; i++)
{
if (_matrices[i].TryFormat(destination, out int charsWritten, "0.00", CultureInfo.InvariantCulture))
length += charsWritten;
}
return length;
}
}