Created
June 7, 2023 09:57
-
-
Save idg10/8ab81fa4c567702040a877c84c1e99ee to your computer and use it in GitHub Desktop.
Benchmarking two different approaches to IAsyncEnumerable.Switch, forcing non-synchronous ValueTask completion
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 SwitchWithBlockingSources | |
{ | |
public readonly static IAsyncEnumerable<IAsyncEnumerable<int>> source = AsyncEnumerable | |
.Range(0, 1000) | |
.SelectAwait(async i => | |
{ | |
await Task.Yield(); | |
return AsyncEnumerable | |
.Range(0, 1000) | |
.SelectAwait(async i => | |
{ | |
await Task.Yield(); | |
return i; | |
}); | |
}); | |
[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