Skip to content

Commit 210c21b

Browse files
committed
Added a benchmark project using BenchmarkDotNet
1 parent 3448be8 commit 210c21b

5 files changed

Lines changed: 66 additions & 5 deletions

File tree

Unidecode.NET.sln

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.4
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33815.320
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{604AAA61-6C9C-4421-9DA5-0805968113A8}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C9018F64-4917-4F4F-8F78-3A674896029D}"
99
ProjectSection(SolutionItems) = preProject
10+
.editorconfig = .editorconfig
1011
LICENSE = LICENSE
1112
readme.md = readme.md
12-
.editorconfig = .editorconfig
1313
EndProjectSection
1414
EndProject
1515
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unidecode.NET", "src\Unidecode.NET.csproj", "{3ED46251-F3F1-43F0-8776-A5055D96BB56}"
@@ -18,6 +18,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8F8EB995-9
1818
EndProject
1919
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unidecode.NET.Tests", "test\Unidecode.NET.Tests.csproj", "{C93F3F13-BFB7-4440-BC52-B1BFAC74EB1B}"
2020
EndProject
21+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{6B823939-68FD-4909-90D9-A6B4BE177ADA}"
22+
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unidecode.NET.Benchmark", "benchmark\Unidecode.NET.Benchmark\Unidecode.NET.Benchmark.csproj", "{BBB60B62-9870-460D-8629-4825D096F9A3}"
24+
EndProject
2125
Global
2226
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2327
Debug|Any CPU = Debug|Any CPU
@@ -32,12 +36,20 @@ Global
3236
{C93F3F13-BFB7-4440-BC52-B1BFAC74EB1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
3337
{C93F3F13-BFB7-4440-BC52-B1BFAC74EB1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
3438
{C93F3F13-BFB7-4440-BC52-B1BFAC74EB1B}.Release|Any CPU.Build.0 = Release|Any CPU
39+
{BBB60B62-9870-460D-8629-4825D096F9A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{BBB60B62-9870-460D-8629-4825D096F9A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{BBB60B62-9870-460D-8629-4825D096F9A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{BBB60B62-9870-460D-8629-4825D096F9A3}.Release|Any CPU.Build.0 = Release|Any CPU
3543
EndGlobalSection
3644
GlobalSection(SolutionProperties) = preSolution
3745
HideSolutionNode = FALSE
3846
EndGlobalSection
3947
GlobalSection(NestedProjects) = preSolution
4048
{3ED46251-F3F1-43F0-8776-A5055D96BB56} = {604AAA61-6C9C-4421-9DA5-0805968113A8}
4149
{C93F3F13-BFB7-4440-BC52-B1BFAC74EB1B} = {8F8EB995-97FD-41CD-B307-E2F8E987C468}
50+
{BBB60B62-9870-460D-8629-4825D096F9A3} = {6B823939-68FD-4909-90D9-A6B4BE177ADA}
51+
EndGlobalSection
52+
GlobalSection(ExtensibilityGlobals) = postSolution
53+
SolutionGuid = {AFE6DE01-A43D-4110-90C8-75C670655EF1}
4254
EndGlobalSection
4355
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using BenchmarkDotNet;
7+
using BenchmarkDotNet.Attributes;
8+
9+
namespace Unidecode.NET.Benchmark;
10+
[MemoryDiagnoser]
11+
public class Benchmarks
12+
{
13+
14+
[Benchmark]
15+
public void UnidecodeRussianTest()
16+
{
17+
var converted = "Работа с кириллицей".Unidecode();
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using BenchmarkDotNet.Running;
2+
3+
namespace Unidecode.NET.Benchmark;
4+
5+
internal class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
var summary = BenchmarkRunner.Run<Benchmarks>();
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Compile Include="..\..\src\Unidecoder.Characters.cs" Link="Unidecoder.Characters.cs" />
12+
<Compile Include="..\..\src\Unidecoder.cs" Link="Unidecoder.cs" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
17+
</ItemGroup>
18+
19+
</Project>

src/Unidecoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static string Unidecode(this string input, int? tempStringBuilderCapacity
3434
if (input.All(x => x < 0x80))
3535
return input;
3636

37-
if (input.Length < MaxStringLengthForStackAlloc)
37+
/* if (input.Length < MaxStringLengthForStackAlloc)
3838
{
3939
Span<char> stackBuffer = stackalloc char[STACKALLOC_BUFFER_SIZE];
4040
int buffIdx = 0;
@@ -57,7 +57,7 @@ public static string Unidecode(this string input, int? tempStringBuilderCapacity
5757
}
5858
5959
return new string(stackBuffer[0..buffIdx]);
60-
}
60+
}*/
6161

6262

6363
// Unidecode result often can be at least two times longer than input string.

0 commit comments

Comments
 (0)