Skip to content

Instantly share code, notes, and snippets.

@idg10
Created June 7, 2023 09:48
Show Gist options
  • Save idg10/4a63ade9e2d15e662ccb3e07272d14a2 to your computer and use it in GitHub Desktop.
Save idg10/4a63ade9e2d15e662ccb3e07272d14a2 to your computer and use it in GitHub Desktop.
Benchmarking two different approaches to IAsyncEnumerable.Switch
[MemoryDiagnoser]
public class SwitchWithNonBlockingSources
{
public readonly static IAsyncEnumerable<IAsyncEnumerable<int>> source = AsyncEnumerable
.Range(0, 1000)
.Select(i => AsyncEnumerable.Range(0, 1000));
[Benchmark]
public async ValueTask<int> IterativeSingleLogicalThread()
{
return await source.Switch().LastAsync();
}
[Benchmark]
public async ValueTask<int> ConcurrentLogicalThreads()
{
return await source.Switch2().LastAsync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment