Skip to content

Instantly share code, notes, and snippets.

View ledjon-behluli's full-sized avatar

Ledjon Behluli ledjon-behluli

View GitHub Profile
@ledjon-behluli
ledjon-behluli / StringSimilarity
Created April 26, 2024 14:45
Zero allocation, approximate string matching
/// <summary>
/// Performs similarity search between two strings using the fuzzy string searching algorithm.
/// </summary>
public static class StringSimilarity
{
/// <returns>A score between 0-100</returns>
public static int GetScore(ReadOnlySpan<char> input1, ReadOnlySpan<char> input2)
{
if (input1.Length == 0 || input2.Length == 0)
{
@ledjon-behluli
ledjon-behluli / AsyncAwaitBenchmarks.cs
Created November 6, 2022 14:41
Do not await what does not need to be awaited
[MemoryDiagnoser][SimpleJob][CategoriesColumn][Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class AsyncAwaitBenchmarks
{
static readonly IWebService webService1 = new NormalWebService();
static readonly IWebService webService2 = new CompletedResultWebService();
[Benchmark, BenchmarkCategory("Normal")]
public async Task<object> GetAsyncNormal_V1() => await webService1.GetAsync();
[Benchmark, BenchmarkCategory("Normal")]
@ledjon-behluli
ledjon-behluli / AsyncOutboxProcessor.cs
Last active September 4, 2021 12:13
Asynchronous implementation of an OutboxProcessor with error recovery.
public class OutboxProcessor : IOutboxProcessor, IHostedService, IDisposable
{
private readonly OutboxProcessorSettings settings;
private readonly ILogger<OutboxProcessor> logger;
private readonly IBusPublisher busPublisher;
private AsyncTimer timer;
public OutboxProcessor(
IBusPublisher busPublisher,