c# - .NET HttpWebRequest Speed versus Browser -
i have question regarding performance of .net httpwebrequest client (or webclient, gives similar results).
if use httpwebrequest request html page (in case news.bbc.co.uk) , analyse speed (using httpanalyzer) @ response read application, slower browser (firefox, chrome, ie) requesting same resource (all caches cleared etc). .net application takes approximately 1.7 seconds versus 0.2 - 0.3 seconds browser.
is purely down speed , efficiency of code / application or there other factors consider?
code follows:
httpwebrequest request = null; uri uritest = new uri("http://news.bbc.co.uk"); request = (httpwebrequest)webrequest.create(uritest); request.method = "get"; request.keepalive = true; request.headers["accept-encoding"] = "gzip, deflate"; httpwebresponse response = (httpwebresponse)request.getresponse(); response.close();
if make 2 requests second 1 happen more quickly?
i have notice speed disparities between browsers , webclient or webrequest. raw speed of response can drastically different - not time!
there few things caused by:
it .net bootstrapping happens. .net assemblies aren't loaded , jitted until used, therefore can see significant speed degradation on initial call piece of code if application has been running ages. okay - .net framework ngen'd - there's still bridge between code , .net framework build on fly.
just checking you're running without debugger attached , don't have symbol server switched on - symbol server , vs interrupts programs symbols downloaded, slowing them down bucket-loads. sorry if insult ;)
browsers coded make efficient use of few underlying sockets; , opened , primed browser there. 'our' code uses .net webclient/webrequest totally inefficient in comparison, initialised anew each time.
there lot of platform resources associated networking, , whilst .net makes easier code networks, it's still bound same platform resource issues. ergo, closer platform are, faster code be. ie , firefox et al native , therefore can thrown around system resources natively; .net isn't , therefore marshalling(=slow) required set things up. obviously, once port opened , being used, however, .net still no slouch; never fast well-written non-marshalled native code.
Comments
Post a Comment