@Felipe Oriani, you where totaly true.. I was curious so i did the test.
See this amazing output.
- Void Avg response time is 2.075 ms
- IHttpActionResult Avg response time is 1.651 ms!
So that is a difference of 0.424 ms
This was with the following webAPI code
[Route("test/void")]
public void GetFirst()
{
StringBuilder stringbuilder = new StringBuilder();
for (int i = 0; i < 20; i++)
{
stringbuilder.Append("something");
}
//Thread.Sleep(1000);
}
[Route("test/IHttpActionResult")]
public IHttpActionResult GetSecond()
{
StringBuilder stringbuilder = new StringBuilder();
for (int i = 0; i < 20; i++)
{
stringbuilder.Append("something");
}
//Thread.Sleep(1000);
return Ok();
}
Also i tried giving the webAPI more work on each request.. to see if the difference stays the same, or if for an longer action it's a real improvement to use IHttpActionResult instead of void?
I set the iteration to 200000 and uncommented the Thread.Sleep(1000) in the WebAPI code
Now the results:
- Void Avg response time is 11.64 ms
- IHttpActionResult Avg response time is 11.11 ms
So that is a difference of 0.53 ms
To which i can conclude and confirm, that what you say is true. And IHttpActionREsult is indeed faster then void. Only the difference is to minor to really notice something. But if your looking for the minor mini optimalisations? this is one of them!
The image below for the result!