Skip to content

Commit edd72dc

Browse files
committed
finished benchmarks
1 parent eb6eb36 commit edd72dc

19 files changed

+617
-261
lines changed

src/Enumerators/Split/SpanSplitWithCountEnumerator.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace SpanExtensions.Enumerators
66
/// Supports iteration over a <see cref="ReadOnlySpan{T}"/> by splitting it a a specified delimiter of type <typeparamref name="T"/> with an upper limit of splits performed.
77
/// </summary>
88
/// <typeparam name="T">The type of elements in the enumerated <see cref="ReadOnlySpan{T}"/>.</typeparam>
9-
public ref struct SpanSplitWithCountEnumerator<T> where T : IEquatable<T>
9+
public ref struct SpanSplitWithCountEnumerator<T> where T : IEquatable<T>
1010
{
1111
ReadOnlySpan<T> Span;
1212
readonly T Delimiter;
1313
readonly int Count;
14-
readonly CountExceedingBehaviour CountExceedingBehaviour;
14+
readonly CountExceedingBehaviour CountExceedingBehaviour;
1515
int currentCount;
1616
bool enumerationDone;
1717
readonly int CountMinusOne;
@@ -68,18 +68,18 @@ public bool MoveNext()
6868
switch(CountExceedingBehaviour)
6969
{
7070
case CountExceedingBehaviour.CutLastElements:
71-
break;
71+
break;
7272
case CountExceedingBehaviour.AppendLastElements:
73-
if(currentCount == CountMinusOne)
73+
if(currentCount == CountMinusOne)
7474
{
75-
ReadOnlySpan<T> lower = span[..index];
76-
ReadOnlySpan<T> upper = span[(index + 1)..];
77-
Span<T> temp = new T[lower.Length + upper.Length];
78-
lower.CopyTo(temp[..index]);
75+
ReadOnlySpan<T> lower = span[..index];
76+
ReadOnlySpan<T> upper = span[(index + 1)..];
77+
Span<T> temp = new T[lower.Length + upper.Length];
78+
lower.CopyTo(temp[..index]);
7979
upper.CopyTo(temp[index..]);
80-
Current = temp;
80+
Current = temp;
8181
currentCount++;
82-
return true;
82+
return true;
8383
}
8484
break;
8585
default:

src/Extensions/ReadOnlySpan/ReadOnlySpanExtensions.Linq.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ public static ReadOnlySpan<T> Take<T>(this ReadOnlySpan<T> source, int count)
315315
public static ReadOnlySpan<T> SkipWhile<T>(this ReadOnlySpan<T> source, Predicate<T> condition)
316316
{
317317
int count = 0;
318-
while (count < source.Length)
318+
while(count < source.Length)
319319
{
320-
T t = source[count];
320+
T t = source[count];
321321
if(!condition(t))
322322
{
323323
return source.Skip(count);

src/InvalidCountExceedingBehaviourException.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class InvalidCountExceedingBehaviourException : Exception
1313
/// </summary>
1414
/// <param name="countExceedingBehaviour"> The invalid <see cref="CountExceedingBehaviour"/>. </param>
1515
public InvalidCountExceedingBehaviourException(CountExceedingBehaviour countExceedingBehaviour) :
16-
base($"CountExceedingBehaviour with ID '{(int) countExceedingBehaviour} is not defined. CountExceedingBehaviour only defines {GetCountExceedingBehaviourNamesListed()}.")
16+
base($"CountExceedingBehaviour with ID '{(int)countExceedingBehaviour} is not defined. CountExceedingBehaviour only defines {GetCountExceedingBehaviourNamesListed()}.")
1717
{
18-
18+
1919
}
2020

2121
static string GetCountExceedingBehaviourNamesListed()
@@ -24,7 +24,7 @@ static string GetCountExceedingBehaviourNamesListed()
2424
#if NET5_0_OR_GREATER
2525
countExceedingBehaviourNames = Enum.GetNames<CountExceedingBehaviour>();
2626
#else
27-
countExceedingBehaviourNames = (string[]) Enum.GetNames(typeof(CountExceedingBehaviour));
27+
countExceedingBehaviourNames = (string[])Enum.GetNames(typeof(CountExceedingBehaviour));
2828
#endif
2929
switch(countExceedingBehaviourNames.Length)
3030
{
@@ -33,7 +33,7 @@ static string GetCountExceedingBehaviourNamesListed()
3333
case 1:
3434
return countExceedingBehaviourNames[0];
3535
default:
36-
string first = countExceedingBehaviourNames[0];
36+
string first = countExceedingBehaviourNames[0];
3737
string end = string.Join(',', countExceedingBehaviourNames, 1, countExceedingBehaviourNames.Length - 1);
3838
return $"{first} and {end}";
3939
}

tests/Performance/Tests/ReadOnlySpan/ReadOnlySpan_Split_Benchmark.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/Performance/Tests/ReadOnlySpan/ReadOnlySpan_Split_Count_Benchmark.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/Performance/Tests/ReadOnlySpan/ReadOnlySpan_Split_Count_StringSplitOptions_Benchmark.cs

Lines changed: 0 additions & 74 deletions
This file was deleted.

tests/Performance/Tests/ReadOnlySpan/ReadOnlySpan_Split_StringSplitOptions_Benchmark.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace SpanExtensions.Tests.Performance;
4+
5+
[MemoryDiagnoser(false)]
6+
public class ReadOnlySpan_Split_Benchmark
7+
{
8+
[Benchmark]
9+
[ArgumentsSource(nameof(GetArgsWithDelimiter))]
10+
public int Split_ReadOnlySpan(ReadOnlySpan<char> value, char delimiter)
11+
{
12+
int length = 0;
13+
14+
foreach(ReadOnlySpan<char> part in value.Split(delimiter))
15+
{
16+
length += part.Length;
17+
}
18+
19+
return length;
20+
}
21+
22+
[Benchmark(Baseline = true)]
23+
[ArgumentsSource(nameof(GetArgsWithDelimiter))]
24+
public int Split_String(string value, char delimiter)
25+
{
26+
int length = 0;
27+
28+
foreach(string part in value.Split(delimiter))
29+
{
30+
length += part.Length;
31+
}
32+
33+
return length;
34+
}
35+
36+
public IEnumerable<object[]> GetArgsWithDelimiter()
37+
{
38+
yield return new object[] { "xyz", 'y' };
39+
yield return new object[] { "abcde", 'c' };
40+
yield return new object[] { "abcdefg", 'd' };
41+
yield return new object[] { "abba", 'b' };
42+
yield return new object[] { "aaa", 'a' };
43+
yield return new object[] { "aba", 'a' };
44+
yield return new object[] { "12131415161718190", '1' };
45+
}
46+
}

0 commit comments

Comments
 (0)