-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathPerf.AsyncMethods.cs
46 lines (39 loc) · 1.23 KB
/
Perf.AsyncMethods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
#pragma warning disable CS1998 // async methods without awaits
namespace System.Threading.Tasks.Tests
{
[BenchmarkCategory(Categories.Libraries, Categories.NoWASM)]
public class Perf_AsyncMethods
{
[Benchmark(OperationsPerInvoke = 100_000)]
public async Task EmptyAsyncMethodInvocation()
{
for (int i = 0; i < 100_000; i++)
{
await EmptyAsync();
}
async Task EmptyAsync() { }
}
[Benchmark(OperationsPerInvoke = 1_000)]
public async Task SingleYieldMethodInvocation()
{
for (int i = 0; i < 1_000; i++)
{
await Yield();
}
async Task Yield() => await Task.Yield();
}
[Benchmark(OperationsPerInvoke = 1_000_000)]
public async Task Yield()
{
for (int i = 0; i < 1_000_000; i++)
{
await Task.Yield();
}
}
}
}