Last active
August 29, 2015 14:14
-
-
Save AlbertoMonteiro/5aaba9af18a45e4a954c to your computer and use it in GitHub Desktop.
Speed
This file contains hidden or 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
| 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) | |
| { | |
| } | |
| } |
This file contains hidden or 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
| 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