Is it expensive?
I am developing an HtmlHelper that renders directly to Response.Output in order to save unnecesary string creation and I need to choose between:
<% Validator.RenderClient(Response.Output); %>
and
<% Validator.RenderClient(); %>
and get the textWriter from HttpContext.Current.Response
@Dawkins
100 runs is too few, you need to run about 10000 times several times and repeat it and then take the average of that to get a reliable result. The margin of error is to big in your example, but it’s the right way to go.
Here’s what i did:
Your result show that there’s a 18% performance difference, which shows that it’s more expensive but it off by 8%.
I re-ran the numbers several times and came up with a 10% difference with a error margin of less then 1%.
It stablaizes around:
Anyway, HttpContext.Current to pose a significant performance problem you’ll need to call it way more than 10000 per request (the cost is largely made up by the Response.Write calls). And that’s likely not going to happen.