Skip to content

Commit fff93b0

Browse files
committed
Bench ASCII for GetIndexOfFirstNonAsciiByte
1 parent 362ac77 commit fff93b0

File tree

6 files changed

+204
-18
lines changed

6 files changed

+204
-18
lines changed

.vscode/launch.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/benchmark/bin/Debug/net7.0/benchmark.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/benchmark",
16+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17+
"console": "internalConsole",
18+
"stopAtEntry": false
19+
},
20+
{
21+
"name": ".NET Core Attach",
22+
"type": "coreclr",
23+
"request": "attach"
24+
}
25+
]
26+
}

.vscode/tasks.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/benchmark/benchmark.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/benchmark/benchmark.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/benchmark/benchmark.csproj"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}

SimdUnicode.sln

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimdUnicode", "src\SimdUnicode.csproj", "{345E0A80-265A-4F37-829E-0763BA0E3C24}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tests", "test\tests.csproj", "{A75C0BBB-5855-405B-8E8F-F28D3000E28B}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "benchmark", "benchmark\benchmark.csproj", "{F70E182A-065F-4568-AFF6-68589357D7B0}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark (1)", "benchmark", "{B37C7A64-B3E6-4C2F-9B13-1057CBB837E2}"
13+
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bin", "bin", "{628CBBA7-057B-4BB6-8B8A-9677CFEAFCF6}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Release", "Release", "{8CAB8789-BE6B-428F-AF80-871A3C27771C}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net7.0", "net7.0", "{D5D4B18F-86AD-40CE-8ECA-9095E7F53CB3}"
19+
EndProject
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.Autogenerated", "benchmark\bin\Release\net7.0\dfbf1592-71b0-4fa8-8a38-75c748e57895\BenchmarkDotNet.Autogenerated.csproj", "{AE5A73D4-15F8-4B3A-8483-16BE5BAB1381}"
21+
EndProject
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.Autogenerated (1)", "benchmark\bin\Release\net7.0\984f4e71-bd9a-4723-99d2-2b82eed027b9\BenchmarkDotNet.Autogenerated.csproj", "{2A1DBF6C-1C4F-44E8-A881-CB045DD146C2}"
23+
EndProject
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.Autogenerated (2)", "benchmark\bin\Release\net7.0\9c6d6db5-a2ed-4981-8b16-701aaa84a42b\BenchmarkDotNet.Autogenerated.csproj", "{C6717075-2C22-4317-B8FB-5A75917B611D}"
25+
EndProject
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.Autogenerated (3)", "benchmark\bin\Release\net7.0\90090881-7d41-439d-baea-2e83fdcedcd4\BenchmarkDotNet.Autogenerated.csproj", "{8AA08360-A97F-43F8-93D5-F23B09D4BC3F}"
27+
EndProject
28+
Global
29+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
30+
Debug|Any CPU = Debug|Any CPU
31+
Release|Any CPU = Release|Any CPU
32+
EndGlobalSection
33+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
34+
{345E0A80-265A-4F37-829E-0763BA0E3C24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{345E0A80-265A-4F37-829E-0763BA0E3C24}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{345E0A80-265A-4F37-829E-0763BA0E3C24}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{345E0A80-265A-4F37-829E-0763BA0E3C24}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{A75C0BBB-5855-405B-8E8F-F28D3000E28B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{A75C0BBB-5855-405B-8E8F-F28D3000E28B}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{A75C0BBB-5855-405B-8E8F-F28D3000E28B}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{A75C0BBB-5855-405B-8E8F-F28D3000E28B}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{F70E182A-065F-4568-AFF6-68589357D7B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{F70E182A-065F-4568-AFF6-68589357D7B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{F70E182A-065F-4568-AFF6-68589357D7B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{F70E182A-065F-4568-AFF6-68589357D7B0}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{AE5A73D4-15F8-4B3A-8483-16BE5BAB1381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{AE5A73D4-15F8-4B3A-8483-16BE5BAB1381}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{AE5A73D4-15F8-4B3A-8483-16BE5BAB1381}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{AE5A73D4-15F8-4B3A-8483-16BE5BAB1381}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{2A1DBF6C-1C4F-44E8-A881-CB045DD146C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{2A1DBF6C-1C4F-44E8-A881-CB045DD146C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{2A1DBF6C-1C4F-44E8-A881-CB045DD146C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{2A1DBF6C-1C4F-44E8-A881-CB045DD146C2}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{C6717075-2C22-4317-B8FB-5A75917B611D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
55+
{C6717075-2C22-4317-B8FB-5A75917B611D}.Debug|Any CPU.Build.0 = Debug|Any CPU
56+
{C6717075-2C22-4317-B8FB-5A75917B611D}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{C6717075-2C22-4317-B8FB-5A75917B611D}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{8AA08360-A97F-43F8-93D5-F23B09D4BC3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{8AA08360-A97F-43F8-93D5-F23B09D4BC3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{8AA08360-A97F-43F8-93D5-F23B09D4BC3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{8AA08360-A97F-43F8-93D5-F23B09D4BC3F}.Release|Any CPU.Build.0 = Release|Any CPU
62+
EndGlobalSection
63+
GlobalSection(SolutionProperties) = preSolution
64+
HideSolutionNode = FALSE
65+
EndGlobalSection
66+
GlobalSection(NestedProjects) = preSolution
67+
{628CBBA7-057B-4BB6-8B8A-9677CFEAFCF6} = {B37C7A64-B3E6-4C2F-9B13-1057CBB837E2}
68+
{8CAB8789-BE6B-428F-AF80-871A3C27771C} = {628CBBA7-057B-4BB6-8B8A-9677CFEAFCF6}
69+
{D5D4B18F-86AD-40CE-8ECA-9095E7F53CB3} = {8CAB8789-BE6B-428F-AF80-871A3C27771C}
70+
{AE5A73D4-15F8-4B3A-8483-16BE5BAB1381} = {D5D4B18F-86AD-40CE-8ECA-9095E7F53CB3}
71+
{2A1DBF6C-1C4F-44E8-A881-CB045DD146C2} = {D5D4B18F-86AD-40CE-8ECA-9095E7F53CB3}
72+
{C6717075-2C22-4317-B8FB-5A75917B611D} = {D5D4B18F-86AD-40CE-8ECA-9095E7F53CB3}
73+
{8AA08360-A97F-43F8-93D5-F23B09D4BC3F} = {D5D4B18F-86AD-40CE-8ECA-9095E7F53CB3}
74+
EndGlobalSection
75+
GlobalSection(ExtensibilityGlobals) = postSolution
76+
SolutionGuid = {7E266F1D-421F-44E1-BE66-B9780F9B7349}
77+
EndGlobalSection
78+
EndGlobal

benchmark/Benchmark.cs

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ namespace SimdUnicodeBenchmarks
1515
public class Checker
1616
{
1717
List<char[]> names;
18+
List<byte[]> AsciiBytes;
1819
List<char[]> nonAsciichars;
19-
public List<byte[]> nonAsciiByteArrays; // Declare at the class level
20+
public List<byte[]> nonAsciiBytes; // Declare at the class level
2021

2122
List<bool> results;
2223

@@ -83,16 +84,20 @@ public static char[] GetRandomNonASCIIString(uint n)
8384
public void Setup()
8485
{
8586
names = new List<char[]>();
86-
nonAsciiByteArrays = new List<byte[]>(); // Initialize the list of byte arrays
87+
nonAsciiBytes = new List<byte[]>(); // Initialize the list of byte arrays
8788
results = new List<bool>();
8889

8990
for (int i = 0; i < 100; i++)
9091
{
9192
names.Add(GetRandomASCIIString(N));
9293
char[] nonAsciiChars = GetRandomNonASCIIString(N);
93-
nonAsciiByteArrays.Add(Encoding.UTF8.GetBytes(nonAsciiChars)); // Convert to byte array and store
94+
nonAsciiBytes.Add(Encoding.UTF8.GetBytes(nonAsciiChars)); // Convert to byte array and store
9495
results.Add(false);
9596
}
97+
98+
AsciiBytes = names
99+
.Select(name => System.Text.Encoding.ASCII.GetBytes(name))
100+
.ToList();
96101
}
97102

98103

@@ -129,30 +134,60 @@ public void RuntimeIsAscii()
129134
}
130135
}
131136
[Benchmark]
132-
public void TestErrorGetIndexOfFirstNonAsciiByteBenchmark()
137+
public void Error_GetIndexOfFirstNonAsciiByte()
138+
{
139+
foreach (byte[] nonAsciiByte in nonAsciiBytes) // Use nonAsciiBytes directly
140+
{
141+
unsafe
142+
{
143+
fixed (byte* pNonAscii = nonAsciiByte)
144+
{
145+
nuint result = SimdUnicode.Ascii.GetIndexOfFirstNonAsciiByte(pNonAscii, (nuint)nonAsciiByte.Length);
146+
}
147+
}
148+
}
149+
}
150+
151+
[Benchmark]
152+
public void Error_Runtime_GetIndexOfFirstNonAsciiByte()
153+
{
154+
foreach (byte[] nonAsciiByte in nonAsciiBytes) // Use nonAsciiBytes directly
155+
{
156+
unsafe
157+
{
158+
fixed (byte* pNonAscii = nonAsciiByte)
159+
{
160+
nuint result = Competition.Ascii.GetIndexOfFirstNonAsciiByte(pNonAscii, (nuint)nonAsciiByte.Length);
161+
}
162+
}
163+
}
164+
}
165+
166+
[Benchmark]
167+
public void allAscii_GetIndexOfFirstNonAsciiByte()
133168
{
134-
foreach (byte[] nonAsciiBytes in nonAsciiByteArrays) // Use nonAsciiByteArrays directly
169+
foreach (byte[] Abyte in AsciiBytes) // Use nonAsciiBytes directly
135170
{
136171
unsafe
137172
{
138-
fixed (byte* pNonAscii = nonAsciiBytes)
173+
fixed (byte* pNonAscii = Abyte)
139174
{
140-
nuint result = SimdUnicode.Ascii.GetIndexOfFirstNonAsciiByte(pNonAscii, (nuint)nonAsciiBytes.Length);
175+
nuint result = SimdUnicode.Ascii.GetIndexOfFirstNonAsciiByte(pNonAscii, (nuint)Abyte.Length);
141176
}
142177
}
143178
}
144179
}
145180

146181
[Benchmark]
147-
public void RuntimeGetIndexOfFirstNonAsciiByteBenchmark()
182+
public void allAscii_Runtime_GetIndexOfFirstNonAsciiByte()
148183
{
149-
foreach (byte[] nonAsciiBytes in nonAsciiByteArrays) // Use nonAsciiByteArrays directly
184+
foreach (byte[] Abyte in AsciiBytes) // Use nonAsciiBytes directly
150185
{
151186
unsafe
152187
{
153-
fixed (byte* pNonAscii = nonAsciiBytes)
188+
fixed (byte* pNonAscii = Abyte)
154189
{
155-
nuint result = Competition.Ascii.GetIndexOfFirstNonAsciiByte(pNonAscii, (nuint)nonAsciiBytes.Length);
190+
nuint result = Competition.Ascii.GetIndexOfFirstNonAsciiByte(pNonAscii, (nuint)Abyte.Length);
156191
}
157192
}
158193
}

benchmark/benchmark.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
89
</PropertyGroup>
910

10-
<ItemGroup>
11-
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
11+
<ItemGroup>
12+
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
1213
</ItemGroup>
1314

14-
<ItemGroup>
15-
<ProjectReference Include="..\src\SimdUnicode.csproj" />
15+
<ItemGroup>
16+
<ProjectReference Include="..\src\SimdUnicode.csproj" />
17+
<ProjectReference Include="..\test\tests.csproj" />
1618
</ItemGroup>
1719

1820
</Project>

test/tests.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
<IsPackable>false</IsPackable>
99
<IsTestProject>true</IsTestProject>
10+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
11+
1012
</PropertyGroup>
1113

1214
<ItemGroup>
@@ -22,8 +24,10 @@
2224
</PackageReference>
2325
</ItemGroup>
2426

25-
<ItemGroup>
26-
<ProjectReference Include="..\src\SimdUnicode.csproj" />
27+
<ItemGroup>
28+
<ProjectReference Include="..\src\SimdUnicode.csproj" />
29+
<!-- <ProjectReference Include="..\test\randomutf8.csproj" /> -->
30+
2731
</ItemGroup>
2832

2933
</Project>

0 commit comments

Comments
 (0)