Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/benchmarks/micro/libraries/System.Memory/ReadOnlySpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
using Consumer = BenchmarkDotNet.Engines.Consumer;
Expand Down Expand Up @@ -95,6 +96,28 @@ public static IEnumerable<object> TrimArguments()
yield return "abcdefg";
}

[Benchmark]
[ArgumentsSource(nameof(IsWhiteSpaceArguments))]
[MemoryRandomization]
public bool IsWhiteSpace(int _, string input) => input.AsSpan().IsWhiteSpace();

public static IEnumerable<object[]> IsWhiteSpaceArguments()
{
const string WhiteSpaceChars = "\t\n\v\f\r\u0085\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000";

yield return new object[] { 001, ""};
yield return new object[] { 002, "0abcdefg" };
yield return new object[] { 010, new string(' ', 01) + "1abcdefg" };
yield return new object[] { 020, new string(' ', 01) + WhiteSpaceChars.Substring(0, 01) + "2abcdefg" };
yield return new object[] { 040, new string(' ', 02) + WhiteSpaceChars.Substring(0, 02) + "4abcdefg" };
yield return new object[] { 060, new string(' ', 03) + WhiteSpaceChars.Substring(0, 03) + "6abcdefg" };
yield return new object[] { 070, new string(' ', 04) + WhiteSpaceChars.Substring(0, 03) + "7abcdefg" };
yield return new object[] { 080, new string(' ', 04) + WhiteSpaceChars.Substring(0, 04) + "8abcdefg" };
yield return new object[] { 090, new string(' ', 05) + WhiteSpaceChars.Substring(0, 04) + "9abcdefg" };
yield return new object[] { 160, new string(' ', 08) + WhiteSpaceChars.Substring(0, 08) + "16abcdefg" };
yield return new object[] { 320, new string(' ', 16) + WhiteSpaceChars.Substring(0, 16) + "32abcdefg" };
}

private static string GenerateInputString(char source, int count, char replaceChar, int replacePos)
{
char[] str = new char[count];
Expand Down
Loading