Created
August 21, 2017 10:08
-
-
Save Szer/09285d8e4cdc9f459037993bbd9f6c13 to your computer and use it in GitHub Desktop.
Test.cs
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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Threading.Tasks.Schedulers; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace Test | |
{ | |
public class Worker | |
{ | |
async Task<int> f(Task<int> input) | |
{ | |
return 1 + await input; // return output | |
} | |
[Benchmark] | |
public void DoWork() | |
{ | |
Task.Factory.StartNew(() => | |
{ | |
var tcs = new TaskCompletionSource<int>(); | |
(var left, var right) = ((Task<int>)null, f(tcs.Task)); | |
for (var i = 0; i < 100000; i++) | |
{ | |
left = f(right); | |
right = left; | |
} | |
tcs.SetResult(-1); | |
}, CancellationToken.None, TaskCreationOptions.None, new StaTaskScheduler(2)).Wait(); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var summary = BenchmarkRunner.Run<Worker>(); | |
Console.WriteLine(summary); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment