-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix race condition in GetResult/SetResult
- Loading branch information
Showing
6 changed files
with
195 additions
and
202 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vs/ | ||
bin/ | ||
obj/ | ||
obj/ | ||
BenchmarkDotNet.Artifacts/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "3.0.100-preview6-012264" | ||
"version": "3.0.100-preview6" | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using PooledAwait; | ||
using System.Threading.Tasks; | ||
|
||
namespace Benchmark | ||
{ | ||
[MemoryDiagnoser, ShortRunJob] | ||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | ||
[CategoriesColumn] | ||
public class ComparisonBenchmarks | ||
{ | ||
private const int InnerOps = 1000; | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(Task), Baseline = true)] | ||
[BenchmarkCategory("int")] | ||
public async Task<int> ViaTaskT() | ||
{ | ||
int sum = 0; | ||
for (int i = 0; i < InnerOps; i++) | ||
sum += await Inner(1, 2).ConfigureAwait(false); | ||
return sum; | ||
static async Task<int> Inner(int x, int y) | ||
{ | ||
int i = x; | ||
await Task.Yield(); | ||
i *= y; | ||
await Task.Yield(); | ||
return 5 * i; | ||
} | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(Task), Baseline = true)] | ||
[BenchmarkCategory("void")] | ||
public async Task ViaTask() | ||
{ | ||
for (int i = 0; i < InnerOps; i++) | ||
await Inner().ConfigureAwait(false); | ||
|
||
static async Task Inner() | ||
{ | ||
await Task.Yield(); | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(ValueTask))] | ||
[BenchmarkCategory("int")] | ||
public async ValueTask<int> ViaValueTaskT() | ||
{ | ||
int sum = 0; | ||
for (int i = 0; i < InnerOps; i++) | ||
sum += await Inner(1, 2).ConfigureAwait(false); | ||
return sum; | ||
static async ValueTask<int> Inner(int x, int y) | ||
{ | ||
int i = x; | ||
await Task.Yield(); | ||
i *= y; | ||
await Task.Yield(); | ||
return 5 * i; | ||
} | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(ValueTask))] | ||
[BenchmarkCategory("void")] | ||
public async ValueTask ViaValueTask() | ||
{ | ||
for (int i = 0; i < InnerOps; i++) | ||
await Inner().ConfigureAwait(false); | ||
static async ValueTask Inner() | ||
{ | ||
await Task.Yield(); | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(PooledValueTask))] | ||
[BenchmarkCategory("int")] | ||
public ValueTask<int> ViaPooledValueTaskT() | ||
{ | ||
return Impl(); // thunks the type back to ValueTaskT | ||
|
||
static async PooledValueTask<int> Impl() | ||
{ | ||
int sum = 0; | ||
for (int i = 0; i < InnerOps; i++) | ||
sum += await Inner(1, 2).ConfigureAwait(false); | ||
return sum; | ||
static async PooledValueTask<int> Inner(int x, int y) | ||
{ | ||
int i = x; | ||
await Task.Yield(); | ||
i *= y; | ||
await Task.Yield(); | ||
return 5 * i; | ||
} | ||
} | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(PooledValueTask))] | ||
[BenchmarkCategory("void")] | ||
public ValueTask ViaPooledValueTask() | ||
{ | ||
return Impl(); // thunks the type back to ValueTaskT | ||
|
||
static async PooledValueTask Impl() | ||
{ | ||
for (int i = 0; i < InnerOps; i++) | ||
await Inner().ConfigureAwait(false); | ||
static async PooledValueTask Inner() | ||
{ | ||
await Task.Yield(); | ||
await Task.Yield(); | ||
} | ||
} | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(PooledTask))] | ||
[BenchmarkCategory("void")] | ||
public Task ViaPooledTask() | ||
{ | ||
return Impl(); // thunks the type back to ValueTaskT | ||
|
||
static async PooledTask Impl() | ||
{ | ||
for (int i = 0; i < InnerOps; i++) | ||
await Inner().ConfigureAwait(false); | ||
static async PooledTask Inner() | ||
{ | ||
await Task.Yield(); | ||
await Task.Yield(); | ||
} | ||
} | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = InnerOps, Description = nameof(PooledTask))] | ||
[BenchmarkCategory("int")] | ||
public Task ViaPooledTaskT() | ||
{ | ||
return Impl(); // thunks the type back to ValueTaskT | ||
|
||
static async PooledTask<int> Impl() | ||
{ | ||
int sum = 0; | ||
for (int i = 0; i < InnerOps; i++) | ||
sum += await Inner(1, 2).ConfigureAwait(false); | ||
return sum; | ||
static async PooledTask<int> Inner(int x, int y) | ||
{ | ||
int i = x; | ||
await Task.Yield(); | ||
i *= y; | ||
await Task.Yield(); | ||
return 5 * i; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.