Last active
August 29, 2015 13:57
-
-
Save yar-shukan/9770086 to your computer and use it in GitHub Desktop.
TaskRun vs Sync
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.Collections.Generic; | |
using System.Diagnostics; | |
using System.Threading.Tasks; | |
using System.Web.Http; | |
namespace MvcApplication1.Controllers | |
{ | |
public class WaitController : ApiController | |
{ | |
[HttpGet] | |
public async Task<long> TaskRunWait() | |
{ | |
return await Task.Run(() => WaitOperation()); | |
} | |
[HttpGet] | |
public long Wait() | |
{ | |
return WaitOperation(); | |
} | |
private static long WaitOperation() | |
{ | |
int waitTime = WaitTimeGenerator.GetWaitTime(); | |
Stopwatch stopwatch = Stopwatch.StartNew(); | |
for (int i = 0; i < waitTime; i++) | |
{ | |
} | |
return stopwatch.ElapsedMilliseconds; | |
} | |
} | |
public static class WaitTimeGenerator | |
{ | |
private const int Seed = 100; | |
private static readonly Random Random = new Random(Seed); | |
public static int GetWaitTime() | |
{ | |
return Random.Next(900000000, 1000000000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.dropbox.com/sh/qtxj5xmbslftlc2/B48RoYarOO - perf tests screenshots
https://www.dropbox.com/s/sty8ep5h4c9lxjc/MvcApplication1.rar - solution archive