-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmark project, some small optimizations (#39)
* Add benchmark project, some small optimizations * Use .NET 8 SDK in build pipeline * Update unit test project to .NET 8 * Make GetProfile protected internal
- Loading branch information
Showing
10 changed files
with
161 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace F23.StringSimilarity.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class Benchmarks | ||
{ | ||
[Benchmark] | ||
public void Cosine() | ||
{ | ||
var cosine = new Cosine(); | ||
_ = cosine.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void Damerau() | ||
{ | ||
var damerau = new Damerau(); | ||
_ = damerau.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void Jaccard() | ||
{ | ||
var jaccard = new Jaccard(); | ||
_ = jaccard.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void JaroWinkler() | ||
{ | ||
var jaro = new JaroWinkler(); | ||
_ = jaro.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void Levenshtein() | ||
{ | ||
var levenshtein = new Levenshtein(); | ||
_ = levenshtein.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void LongestCommonSubsequence() | ||
{ | ||
var lcs = new LongestCommonSubsequence(); | ||
_ = lcs.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void MetricLCS() | ||
{ | ||
var metricLcs = new MetricLCS(); | ||
_ = metricLcs.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void NGram() | ||
{ | ||
var ngram = new NGram(); | ||
_ = ngram.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void NormalizedLevenshtein() | ||
{ | ||
var normalizedLevenshtein = new NormalizedLevenshtein(); | ||
_ = normalizedLevenshtein.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void OptimalStringAlignment() | ||
{ | ||
var osa = new OptimalStringAlignment(); | ||
_ = osa.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void QGram() | ||
{ | ||
var qGram = new QGram(); | ||
_ = qGram.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void RatcliffObershelp() | ||
{ | ||
var ratcliffObershelp = new RatcliffObershelp(); | ||
_ = ratcliffObershelp.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void SorensenDice() | ||
{ | ||
var sorensenDice = new SorensenDice(); | ||
_ = sorensenDice.Distance("hello", "world"); | ||
} | ||
|
||
[Benchmark] | ||
public void WeightedLevenshtein() | ||
{ | ||
var weightedLevenshtein = new WeightedLevenshtein(new ExampleCharSub()); | ||
_ = weightedLevenshtein.Distance("hello", "world"); | ||
} | ||
|
||
private class ExampleCharSub : ICharacterSubstitution | ||
{ | ||
public double Cost(char c1, char c2) | ||
{ | ||
// The cost for substituting 't' and 'r' is considered smaller as these 2 are located next to each other on a keyboard | ||
if (c1 == 't' && c2 == 'r') return 0.5; | ||
|
||
// For most cases, the cost of substituting 2 characters is 1.0 | ||
return 1.0; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
F23.StringSimilarity.Benchmarks/F23.StringSimilarity.Benchmarks.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\F23.StringSimilarity\F23.StringSimilarity.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using BenchmarkDotNet.Running; | ||
using F23.StringSimilarity.Benchmarks; | ||
|
||
BenchmarkRunner.Run<Benchmarks>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters