-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b56dc3
commit 35128d1
Showing
8 changed files
with
465 additions
and
469 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 |
---|---|---|
@@ -1,47 +1,46 @@ | ||
namespace Fastenshtein.Benchmarking | ||
{ | ||
public class BenchmarkSmallWordsSingleThread : FastenshteinBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(90, 5); | ||
} | ||
|
||
public class BenchmarkNormalWordsSingleThread : FastenshteinBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(60, 20); | ||
} | ||
|
||
public class BenchmarkLargeWordsSingleThread : FastenshteinBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(10, 400); | ||
} | ||
|
||
public class CompetitiveBenchmarkSmallWordsSingleThread : CompetitiveSingleThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(90, 5); | ||
} | ||
|
||
public class CompetitiveBenchmarkNormalWordsSingleThread : CompetitiveSingleThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(60, 20); | ||
} | ||
|
||
public class CompetitiveBenchmarkLargeWordsSingleThread : CompetitiveSingleThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(20, 400); | ||
} | ||
|
||
public class CompetitiveBenchmarkSmallWordsMultiThread : CompetitiveMultiThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(100, 5); | ||
} | ||
|
||
public class CompetitiveBenchmarkNormalWordsMultiThread : CompetitiveMultiThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(90, 20); | ||
} | ||
|
||
public class CompetitiveBenchmarkLargeWordsMultiThread : CompetitiveMultiThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(50, 400); | ||
} | ||
namespace Fastenshtein.Benchmarking; | ||
|
||
public class BenchmarkSmallWordsSingleThread : FastenshteinBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(90, 5); | ||
} | ||
|
||
public class BenchmarkNormalWordsSingleThread : FastenshteinBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(60, 20); | ||
} | ||
|
||
public class BenchmarkLargeWordsSingleThread : FastenshteinBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(10, 400); | ||
} | ||
|
||
public class CompetitiveBenchmarkSmallWordsSingleThread : CompetitiveSingleThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(90, 5); | ||
} | ||
|
||
public class CompetitiveBenchmarkNormalWordsSingleThread : CompetitiveSingleThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(60, 20); | ||
} | ||
|
||
public class CompetitiveBenchmarkLargeWordsSingleThread : CompetitiveSingleThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(20, 400); | ||
} | ||
|
||
public class CompetitiveBenchmarkSmallWordsMultiThread : CompetitiveMultiThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(100, 5); | ||
} | ||
|
||
public class CompetitiveBenchmarkNormalWordsMultiThread : CompetitiveMultiThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(90, 20); | ||
} | ||
|
||
public class CompetitiveBenchmarkLargeWordsMultiThread : CompetitiveMultiThreadBenchmark | ||
{ | ||
protected override string[] CreateTestData() => RandomWords.Create(50, 400); | ||
} |
210 changes: 107 additions & 103 deletions
210
benchmarks/Fastenshtein.Benchmarking/CompetitiveMultiThreadBenchmark.cs
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 |
---|---|---|
@@ -1,128 +1,132 @@ | ||
namespace Fastenshtein.Benchmarking | ||
namespace Fastenshtein.Benchmarking; | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using System.Threading.Tasks; | ||
|
||
[RankColumn] | ||
public abstract class CompetitiveMultiThreadBenchmark | ||
{ | ||
using BenchmarkDotNet.Attributes; | ||
using System.Threading.Tasks; | ||
private string[] _words; | ||
|
||
[RankColumn] | ||
public abstract class CompetitiveMultiThreadBenchmark | ||
{ | ||
protected string[] words; | ||
protected abstract string[] CreateTestData(); | ||
|
||
protected abstract string[] CreateTestData(); | ||
[GlobalSetup] | ||
public void SetUp() | ||
=> _words = CreateTestData(); | ||
|
||
[GlobalSetup] | ||
public void SetUp() | ||
{ | ||
this.words = this.CreateTestData(); | ||
} | ||
|
||
/* | ||
* To add your own Levenshtein to the benchmarking alter the below code. | ||
* Replace YourLevenshtein with your method. | ||
*/ | ||
////[Benchmark] | ||
////public void YourLevenshtein() | ||
////{ | ||
//// Parallel.For(0, words.Length, i => | ||
//// { | ||
//// for (int j = 0; j < words.Length; j++) | ||
//// { | ||
//// YourLevenshtein(words[i], words[j]); | ||
//// } | ||
//// }); | ||
////} | ||
|
||
[Benchmark] | ||
public void Fastenshtein() | ||
/* | ||
* To add your own Levenshtein to the benchmarking alter the below code. | ||
* Replace YourLevenshtein with your method. | ||
*/ | ||
////[Benchmark] | ||
////public void YourLevenshtein() | ||
////{ | ||
//// Parallel.For(0, words.Length, i => | ||
//// { | ||
//// for (int j = 0; j < words.Length; j++) | ||
//// { | ||
//// YourLevenshtein(words[i], words[j]); | ||
//// } | ||
//// }); | ||
////} | ||
|
||
[Benchmark] | ||
public void Fastenshtein() | ||
{ | ||
var words = _words; | ||
Parallel.For(0, words.Length, i => | ||
{ | ||
Parallel.For(0, words.Length, i => | ||
var levenshtein = new global::Fastenshtein.Levenshtein(words[i]); | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
var levenshtein = new global::Fastenshtein.Levenshtein(words[i]); | ||
levenshtein.DistanceFrom(words[j]); | ||
} | ||
}); | ||
} | ||
|
||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
levenshtein.DistanceFrom(words[j]); | ||
} | ||
}); | ||
} | ||
[Benchmark] | ||
public void FastenshteinStatic() | ||
{ | ||
var words = _words; | ||
Parallel.For(0, words.Length, i => | ||
{ | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
global::Fastenshtein.Levenshtein.Distance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void FastenshteinStatic() | ||
[Benchmark(Baseline = true)] | ||
public void Fastenshtein_1_0_0_8() | ||
{ | ||
var words = _words; | ||
Parallel.For(0, words.Length, i => | ||
{ | ||
Parallel.For(0, words.Length, i => | ||
var levenshtein = new global::Fastenshtein.Benchmarking.FastenshteinOld.Fastenshtein_1_0_0_8(words[i]); | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
global::Fastenshtein.Levenshtein.Distance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public void Fastenshtein_1_0_0_8() | ||
levenshtein.DistanceFrom(words[j]); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void FastenshteinStatic_1_0_0_8() | ||
{ | ||
var words = _words; | ||
Parallel.For(0, words.Length, i => | ||
{ | ||
Parallel.For(0, words.Length, i => | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
var levenshtein = new global::Fastenshtein.Benchmarking.FastenshteinOld.Fastenshtein_1_0_0_8(words[i]); | ||
global::Fastenshtein.Benchmarking.FastenshteinOld.Fastenshtein_1_0_0_8.Distance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
|
||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
levenshtein.DistanceFrom(words[j]); | ||
} | ||
}); | ||
} | ||
[Benchmark] | ||
public void StringSimilarity() | ||
{ | ||
// I've read the source code it is thread safe | ||
var lev = new global::F23.StringSimilarity.Levenshtein(); | ||
|
||
[Benchmark] | ||
public void FastenshteinStatic_1_0_0_8() | ||
var words = _words; | ||
Parallel.For(0, words.Length, i => | ||
{ | ||
Parallel.For(0, words.Length, i => | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
global::Fastenshtein.Benchmarking.FastenshteinOld.Fastenshtein_1_0_0_8.Distance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void StringSimilarity() | ||
{ | ||
// I've read the source code it is thread safe | ||
var lev = new global::F23.StringSimilarity.Levenshtein(); | ||
// why does it return a double ?? | ||
lev.Distance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
|
||
Parallel.For(0, words.Length, i => | ||
{ | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
// why does it return a double ?? | ||
lev.Distance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void NinjaNye() | ||
[Benchmark] | ||
public void NinjaNye() | ||
{ | ||
var words = _words; | ||
Parallel.For(0, words.Length, i => | ||
{ | ||
Parallel.For(0, words.Length, i => | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
global::NinjaNye.SearchExtensions.Levenshtein.LevenshteinProcessor.LevenshteinDistance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
global::NinjaNye.SearchExtensions.Levenshtein.LevenshteinProcessor.LevenshteinDistance(words[i], words[j]); | ||
} | ||
}); | ||
} | ||
|
||
|
||
[Benchmark] | ||
public void FuzzyStringsNetStandard() | ||
[Benchmark] | ||
public void FuzzyStringsNetStandard() | ||
{ | ||
var words = _words; | ||
Parallel.For(0, words.Length, i => | ||
{ | ||
Parallel.For(0, words.Length, i => | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
for (int j = 0; j < words.Length; j++) | ||
{ | ||
global::DuoVia.FuzzyStrings.LevenshteinDistanceExtensions.LevenshteinDistance(words[i], words[j], true); | ||
} | ||
}); | ||
} | ||
global::DuoVia.FuzzyStrings.LevenshteinDistanceExtensions.LevenshteinDistance(words[i], words[j], true); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.