Should i use HttpResponse.End() for a fast webapp?
HttpResponse.End() seems to throw an exception according to msdn. Right now i have the choice of returning a value to say end thread (it only goes 2 functions deep) or i can call end().
I know that throwing exceptions is significantly slower (read the comment for a C#/.NET test) so if i want a fast webapp should i consider not calling it when it is trivially easy to not call it?
-edit- I do have a function call in certain functions and in the constructor in classes to ensure the user is logged in. So i call HttpResponse.End() in enough places although hopefully in regular sit开发者_开发技巧e usage it doesn't occur too often.
Just use Response.End
. Write your code for maintainability before you write it for performance.
Besides, the performance measure that matters for web apps is scalability. That is, you should not be asking "how fast can I process this single request", but "how many requests can I process at the same time?".
Exceptions do not affect your scalability, and in the grand scheme of things, an extra couple of microseconds on a single request is nothing: remember it'll be at least 50 milliseconds in network roundtrip: another 100 microseconds is noise.
You could use HttpResponse.Flush to push data to the client instead of terminating the request completely, avoiding the potential exception being thrown.
Note: That exception is not always thrown when Response.End is called, only when you prematurely end a request.
精彩评论