Skip to content

Commit 2a3d851

Browse files
committed
Add SearchValuesTest
1 parent 9ee8216 commit 2a3d851

File tree

5 files changed

+63
-16
lines changed

5 files changed

+63
-16
lines changed

src/Tests/StringFormatTest/BenchmarkTest.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
namespace StringFormatTest;
55

6-
[SimpleJob(RuntimeMoniker.Net50)]
7-
[SimpleJob(RuntimeMoniker.Net60)]
86
[SimpleJob(RuntimeMoniker.Net80)]
97
[SimpleJob(RuntimeMoniker.Net90)]
108
[MemoryDiagnoser]
@@ -14,41 +12,35 @@ public class BenchmarkTest
1412
#region Methods
1513

1614
[Benchmark]
17-
#pragma warning disable IDE0079 // Remove unnecessary suppression
1815
#pragma warning disable CA1822 // Mark members as static
1916
public void BoxFormatTest()
2017
#pragma warning restore CA1822 // Mark members as static
21-
#pragma warning restore IDE0079 // Remove unnecessary suppression
2218
{
2319
_ = Program.BoxFormatTest();
2420
}
2521

2622
//[Benchmark]
27-
#pragma warning disable IDE0079 // Remove unnecessary suppression
2823
#pragma warning disable CA1822 // Mark members as static
2924
public void BoxTest()
3025
#pragma warning restore CA1822 // Mark members as static
31-
#pragma warning restore IDE0079 // Remove unnecessary suppression
3226
{
3327
_ = Program.BoxTest();
3428
}
3529

3630
[Benchmark]
37-
#pragma warning disable IDE0079 // Remove unnecessary suppression
3831
#pragma warning disable CA1822 // Mark members as static
3932
public void UnBoxFormatTest()
4033
#pragma warning restore CA1822 // Mark members as static
41-
#pragma warning restore IDE0079 // Remove unnecessary suppression
34+
4235
{
4336
_ = Program.UnBoxFormatTest();
4437
}
4538

4639
//[Benchmark]
47-
#pragma warning disable IDE0079 // Remove unnecessary suppression
4840
#pragma warning disable CA1822 // Mark members as static
4941
public void UnBoxTest()
5042
#pragma warning restore CA1822 // Mark members as static
51-
#pragma warning restore IDE0079 // Remove unnecessary suppression
43+
5244
{
5345
_ = Program.UnBoxTest();
5446
}

src/Tests/StringFormatTest/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private static void Main(string[] args)
99
{
1010
//ValueStringBuilderTest.Test();
1111

12-
StringBuilderCacheTest.Test();
12+
//StringBuilderCacheTest.Test();
1313

1414
//_ = BenchmarkRunner.Run<BenchmarkTest>();
1515

@@ -53,6 +53,8 @@ private static void Main(string[] args)
5353
//Print.Microsecond(watch);
5454
////233,697 us
5555
////277,426 us
56+
57+
SearchValuesTest.Test();
5658
}
5759

5860
public static string BoxFormatTest()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Buffers;
3+
4+
namespace StringFormatTest;
5+
6+
internal static class SearchValuesTest
7+
{
8+
9+
#region Constants & Statics
10+
11+
private const string Haystack = """
12+
The Project Gutenberg eBook of The Adventures of Sherlock Holmes,
13+
by Arthur Conan Doyle
14+
15+
This eBook is for the use of anyone anywhere in the United States and
16+
most other parts of the world at no cost and with almost no restrictions
17+
whatsoever.
18+
You may copy it, give it away or re-use it under the terms
19+
of the Project Gutenberg License included with this eBook or online at
20+
www.gutenberg.org. If you are not located in the United States, you
21+
will have to check the laws of the country where you are located before
22+
using this eBook.
23+
24+
Title: The Adventures of Sherlock Holmes
25+
26+
Author: Arthur Conan Doyle
27+
28+
Release Date: November 29, 2002 [eBook #1661]
29+
[Most recently updated: October 10, 2023]
30+
31+
Language: English
32+
33+
Character set encoding: UTF-8
34+
35+
Produced by: an anonymous Project Gutenberg volunteer and Jose Menendez
36+
37+
*** START OF THE PROJECT GUTENBERG EBOOK THE ADVENTURES OF SHERLOCK
38+
HOLMES ***
39+
""";
40+
41+
private static readonly SearchValues<char> LineEndings = SearchValues.Create("\n\r\f\u0085\u2028\u2029");
42+
43+
#endregion
44+
45+
#region Methods
46+
47+
internal static void Test()
48+
{
49+
ReadOnlySpan<char> haystack = Haystack;
50+
var pos = haystack.IndexOfAny(LineEndings);
51+
Console.WriteLine(pos);
52+
}
53+
54+
#endregion
55+
56+
}

src/Tests/StringFormatTest/StringFormatTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
5+
<TargetFrameworks>net9.0</TargetFrameworks>
66
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
77
</PropertyGroup>
88

src/plugins/NewtonsoftJsonTest/NewtonsoftJsonTest.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
1212
<CompilerGeneratedFilesOutputPath>_Generated</CompilerGeneratedFilesOutputPath>
1313
</PropertyGroup>
14+
1415
<ItemGroup>
1516
<Compile Remove="_Generated\**\*.g.cs" />
1617
<None Include="_Generated\**\*.g.cs" />
@@ -20,8 +21,4 @@
2021
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2122
</ItemGroup>
2223

23-
<ItemGroup>
24-
<Folder Include="_Generated\System.Text.Json.SourceGeneration\" />
25-
</ItemGroup>
26-
2724
</Project>

0 commit comments

Comments
 (0)