using System.Threading.Tasks;
public static class Program
public static async Task Main()
static ValueTask<int> GetSomeValueAsync(int number) => ValueTask.FromResult(42);
static async Task<int> CallingMethodAsyncTask(int number) => await GetSomeValueAsync(number) + 1;
static async ValueTask<int> CallingMethodAsyncValueTask(int number) => await GetSomeValueAsync(number) + 1;
await CallingMethodAsyncTask(1);
await CallingMethodAsyncValueTask(1);
const int iterations = 1_000;
long totalAllocatedBytes;
totalAllocatedBytes = GC.GetTotalAllocatedBytes();
for (int i = 0; i < iterations; i++) { await CallingMethodAsyncValueTask(i); }
Console.WriteLine($"{nameof(CallingMethodAsyncValueTask)}: {(GC.GetTotalAllocatedBytes() - totalAllocatedBytes) / iterations:#,0} bytes per operation");
totalAllocatedBytes = GC.GetTotalAllocatedBytes();
for (int i = 0; i < iterations; i++) { await CallingMethodAsyncTask(i); }
Console.WriteLine($"{nameof(CallingMethodAsyncTask)}: {(GC.GetTotalAllocatedBytes() - totalAllocatedBytes) / iterations:#,0} bytes per operation");