Skip to content

Instantly share code, notes, and snippets.

@AlbertoMonteiro
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save AlbertoMonteiro/5aaba9af18a45e4a954c to your computer and use it in GitHub Desktop.

Select an option

Save AlbertoMonteiro/5aaba9af18a45e4a954c to your computer and use it in GitHub Desktop.
Speed
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post([FromBody]string value)
{
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
class Program
{
static void Main(string[] args)
{
GetValue();
Console.ReadLine();
}
private static async void GetValue()
{
var requests = 0;
var tasks = Enumerable.Range(1, 3).Select(x => Task.Factory.StartNew(() =>
{
var a = 1;
var b = 1;
while (a == b)
{
var http = HttpWebRequest.CreateHttp("http://localhost:1293/api/values/1");
http.GetResponse();
requests++;
}
}));
Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(10));
Console.WriteLine(requests / 10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment