You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The addition of Span<T> in .NET Core 2.1 can offer some performance
improvements moving through the array in SafeProxy by reducing the
number of arithmetic operations.
.NET Core 3.0 also adds Span<byte> based overloads to HashAlgorithm
which can further improve performance if explicitly supported. If not
supported, any requests to the Span<byte> overloads are copied to an
array before processing.
A BenchmarkDotNet project was also added to assist with benchmarking.
Test results across several target frameworks comparing the pre and post
change performance against a 65536 byte array. These metrics are for
calls in via the array overloads, not the Span<byte> overloads. They
show an approximately 25% reduction in runtime on .NET Core 2.1 and 3.1.
| Method | Runtime | Size | Mean | Error | StdDev | Ratio | Rank |
|------- |-------------- |------ |---------:|---------:|---------:|------:|-----:|
| Array | .NET 4.6.1 | 65536 | 48.08 us | 0.192 us | 0.170 us | 1.00 | 1 |
| Span | .NET 4.6.1 | 65536 | 47.87 us | 0.169 us | 0.150 us | 1.00 | 1 |
| | | | | | | | |
| Array | .NET Core 2.1 | 65536 | 48.99 us | 0.260 us | 0.217 us | 1.00 | 2 |
| Span | .NET Core 2.1 | 65536 | 37.02 us | 0.261 us | 0.218 us | 0.76 | 1 |
| | | | | | | | |
| Array | .NET Core 3.1 | 65536 | 50.01 us | 0.335 us | 0.297 us | 1.00 | 2 |
| Span | .NET Core 3.1 | 65536 | 37.04 us | 0.218 us | 0.204 us | 0.74 | 1 |
@@ -94,6 +114,18 @@ public static uint Compute(byte[] input)
94
114
returnAppend(0,input);
95
115
}
96
116
117
+
#if NETCORE20||NETCORE30
118
+
/// <summary>
119
+
/// Computes CRC-32 from input buffer.
120
+
/// </summary>
121
+
/// <param name="input">Input buffer with data to be checksummed.</param>
122
+
/// <returns>CRC-32 of the data in the buffer.</returns>
123
+
publicstaticuintCompute(ReadOnlySpan<byte>input)
124
+
{
125
+
returnAppend(0,input);
126
+
}
127
+
#endif
128
+
97
129
/// <summary>
98
130
/// Computes CRC-32 from input buffer and writes it after end of data (buffer should have 4 bytes reserved space for it). Can be used in conjunction with <see cref="IsValidWithCrcAtEnd(byte[],int,int)"/>
99
131
/// </summary>
@@ -162,12 +194,22 @@ public override void Initialize()
0 commit comments