Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autypo" Version="1.0.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.4" />
<PackageReference Include="Bogus" Version="35.6.4" />
<PackageReference Include="Fastenshtein" Version="1.0.11" />
Expand Down
33 changes: 32 additions & 1 deletion Akade.IndexedSet.Benchmarks/PrefixIndexBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using BenchmarkDotNet.Attributes;
using Autypo;
using Autypo.Configuration;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using Bogus;

Expand All @@ -11,6 +13,8 @@ public class PrefixIndexBenchmarks
{
private readonly List<Person> _persons;
private readonly IndexedSet<Person> _indexedSet;
private IAutypoSearch<Person> _autoTypo = null!;
private IAutypoSearch<Person> _autoTypoFuzzy = null!;

public PrefixIndexBenchmarks()
{
Expand All @@ -22,6 +26,19 @@ public PrefixIndexBenchmarks()
_indexedSet = _persons.ToIndexedSet()
.WithPrefixIndex(x => x.FullName)
.Build();

}

[GlobalSetup]
public async Task InitAsync()
{
_autoTypo = await AutypoFactory.CreateSearchAsync<Person>(config =>
config.WithDataSource(_persons)
.WithIndex(x => x.FullName, x => x.WithFuzziness(0)));

_autoTypoFuzzy = await AutypoFactory.CreateSearchAsync<Person>(config =>
config.WithDataSource(_persons)
.WithIndex(x => x.FullName, x => x.WithFuzziness(2)));
}

[Benchmark(Baseline = true)]
Expand All @@ -38,6 +55,13 @@ public Person[] StartsWith_IndexedSet()
return _indexedSet.StartsWith(x => x.FullName, "Tiffany").ToArray();
}

[Benchmark]
[BenchmarkCategory("StartsWith")]
public Person[] StartsWith_Autypo()
{
return _autoTypo.Search("Tiffany").Select(x => x.Value).ToArray();
}

[Benchmark(Baseline = true)]
[BenchmarkCategory("Fuzzy StartsWith")]
public Person[] FuzzyStartsWith_Linq()
Expand All @@ -51,4 +75,11 @@ public Person[] FuzzyStartsWith_IndexedSet()
{
return _indexedSet.FuzzyStartsWith(x => x.FullName, "Tiffany", 2).ToArray();
}

[Benchmark]
[BenchmarkCategory("Fuzzy StartsWith")]
public Person[] FuzzyStartsWith_Autypo()
{
return _autoTypoFuzzy.Search("Tiffany").Select(x => x.Value).ToArray();
}
}
Loading