Created
June 7, 2023 09:48
-
-
Save idg10/4a63ade9e2d15e662ccb3e07272d14a2 to your computer and use it in GitHub Desktop.
Benchmarking two different approaches to IAsyncEnumerable.Switch
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
[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