diff options
author | Stephen Toub <stoub@microsoft.com> | 2018-04-09 21:41:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-09 21:41:25 +0300 |
commit | d66a9cda99411be67f6785d0551154c07d0362ac (patch) | |
tree | 81e3a58df3d74e67055be2ac2fc34c62321222c2 | |
parent | e3674c0cc08c82bd50a4b5d1fea950f245164e6c (diff) |
Add more ValueTask perf tests (#28937)
-rw-r--r-- | src/Common/tests/System/Threading/Tasks/Sources/ManualResetValueTaskSource.cs (renamed from src/System.Threading.Tasks.Extensions/tests/ManualResetValueTaskSource.cs) | 0 | ||||
-rw-r--r-- | src/System.Threading.Tasks.Extensions/tests/Performance/Perf.ValueTask.cs | 70 | ||||
-rw-r--r-- | src/System.Threading.Tasks.Extensions/tests/Performance/System.Threading.Tasks.Extensions.Performance.Tests.csproj | 3 | ||||
-rw-r--r-- | src/System.Threading.Tasks.Extensions/tests/System.Threading.Tasks.Extensions.Tests.csproj | 4 |
4 files changed, 76 insertions, 1 deletions
diff --git a/src/System.Threading.Tasks.Extensions/tests/ManualResetValueTaskSource.cs b/src/Common/tests/System/Threading/Tasks/Sources/ManualResetValueTaskSource.cs index 4e6c328038..4e6c328038 100644 --- a/src/System.Threading.Tasks.Extensions/tests/ManualResetValueTaskSource.cs +++ b/src/Common/tests/System/Threading/Tasks/Sources/ManualResetValueTaskSource.cs diff --git a/src/System.Threading.Tasks.Extensions/tests/Performance/Perf.ValueTask.cs b/src/System.Threading.Tasks.Extensions/tests/Performance/Perf.ValueTask.cs index 27c335dd3a..0124d3a3a3 100644 --- a/src/System.Threading.Tasks.Extensions/tests/Performance/Perf.ValueTask.cs +++ b/src/System.Threading.Tasks.Extensions/tests/Performance/Perf.ValueTask.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Threading.Tasks.Sources; +using System.Threading.Tasks.Tests; using Microsoft.Xunit.Performance; using Xunit; @@ -45,6 +47,23 @@ namespace System.Threading.Tasks } [Benchmark(InnerIterationCount = 10_000_000), MeasureGCAllocations] + public async Task Await_FromCompletedValueTaskSource() + { + ValueTask<int> vt = new ValueTask<int>(ManualResetValueTaskSource.Completed<int>(42), 0); + foreach (BenchmarkIteration iteration in Benchmark.Iterations) + { + long iters = Benchmark.InnerIterationCount; + using (iteration.StartMeasurement()) + { + for (long i = 0; i < iters; i++) + { + await vt; + } + } + } + } + + [Benchmark(InnerIterationCount = 10_000_000), MeasureGCAllocations] public async Task CreateAndAwait_FromResult() { foreach (BenchmarkIteration iteration in Benchmark.Iterations) @@ -110,6 +129,40 @@ namespace System.Threading.Tasks } } + [Benchmark(InnerIterationCount = 10_000_000), MeasureGCAllocations] + public async Task CreateAndAwait_FromCompletedValueTaskSource() + { + IValueTaskSource<int> vts = ManualResetValueTaskSource.Completed(42); + foreach (BenchmarkIteration iteration in Benchmark.Iterations) + { + long iters = Benchmark.InnerIterationCount; + using (iteration.StartMeasurement()) + { + for (long i = 0; i < iters; i++) + { + await new ValueTask<int>(vts, 0); + } + } + } + } + + [Benchmark(InnerIterationCount = 10_000_000), MeasureGCAllocations] + public async Task CreateAndAwait_FromCompletedValueTaskSource_ConfigureAwait() + { + IValueTaskSource<int> vts = ManualResetValueTaskSource.Completed(42); + foreach (BenchmarkIteration iteration in Benchmark.Iterations) + { + long iters = Benchmark.InnerIterationCount; + using (iteration.StartMeasurement()) + { + for (long i = 0; i < iters; i++) + { + await new ValueTask<int>(vts, 0).ConfigureAwait(false); + } + } + } + } + [Benchmark(InnerIterationCount = 1_000_000), MeasureGCAllocations] public async Task CreateAndAwait_FromYieldingAsyncMethod() { @@ -179,6 +232,23 @@ namespace System.Threading.Tasks } } + [Benchmark(InnerIterationCount = 10_000_000), MeasureGCAllocations] + public void Copy_PassAsArgumentAndReturn_FromValueTaskSource() + { + ValueTask<int> vt = new ValueTask<int>(ManualResetValueTaskSource.Completed(42), 0); + foreach (BenchmarkIteration iteration in Benchmark.Iterations) + { + long iters = Benchmark.InnerIterationCount; + using (iteration.StartMeasurement()) + { + for (long i = 0; i < iters; i++) + { + vt = ReturnValueTask(vt); + } + } + } + } + [MethodImpl(MethodImplOptions.NoInlining)] private static ValueTask<int> ReturnValueTask(ValueTask<int> vt) => vt; diff --git a/src/System.Threading.Tasks.Extensions/tests/Performance/System.Threading.Tasks.Extensions.Performance.Tests.csproj b/src/System.Threading.Tasks.Extensions/tests/Performance/System.Threading.Tasks.Extensions.Performance.Tests.csproj index 7a173afdaf..d7137b792f 100644 --- a/src/System.Threading.Tasks.Extensions/tests/Performance/System.Threading.Tasks.Extensions.Performance.Tests.csproj +++ b/src/System.Threading.Tasks.Extensions/tests/Performance/System.Threading.Tasks.Extensions.Performance.Tests.csproj @@ -13,6 +13,9 @@ <Compile Include="$(CommonTestPath)\System\PerfUtils.cs"> <Link>Common\System\PerfUtils.cs</Link> </Compile> + <Compile Include="$(CommonTestPath)\System\Threading\Tasks\Sources\ManualResetValueTaskSource.cs"> + <Link>Common\System\Threading\Tasks\Sources\ManualResetValueTaskSource.cs</Link> + </Compile> </ItemGroup> <ItemGroup> <ProjectReference Include="$(CommonPath)\..\perf\PerfRunner\PerfRunner.csproj"> diff --git a/src/System.Threading.Tasks.Extensions/tests/System.Threading.Tasks.Extensions.Tests.csproj b/src/System.Threading.Tasks.Extensions/tests/System.Threading.Tasks.Extensions.Tests.csproj index e9791a458a..163a74c9fe 100644 --- a/src/System.Threading.Tasks.Extensions/tests/System.Threading.Tasks.Extensions.Tests.csproj +++ b/src/System.Threading.Tasks.Extensions/tests/System.Threading.Tasks.Extensions.Tests.csproj @@ -13,8 +13,10 @@ <ItemGroup> <Compile Include="AsyncMethodBuilderAttributeTests.cs" /> <Compile Include="AsyncValueTaskMethodBuilderTests.cs" /> - <Compile Include="ManualResetValueTaskSource.cs" /> <Compile Include="ValueTaskTests.cs" /> + <Compile Include="$(CommonTestPath)\System\Threading\Tasks\Sources\ManualResetValueTaskSource.cs"> + <Link>Common\System\Threading\Tasks\Sources\ManualResetValueTaskSource.cs</Link> + </Compile> </ItemGroup> <ItemGroup> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> |