.NET HttpWebRequest Speed versus Browser

前端 未结 9 1107
深忆病人
深忆病人 2020-12-29 13:01

I have a question regarding the performance of the .Net HttpWebRequest client (or WebClient, gives similar results).

If I use HttpWebRequest to request an html page

9条回答
  •  情歌与酒
    2020-12-29 13:46

    Run the application with Ctrl+F5 instead of F5 (Debug mode). You will see a difference:

    class Program
    {
        static void Main()
        {
            using (var client = new WebClient())
            {
                Stopwatch watch = Stopwatch.StartNew();
                var data = client.DownloadData("http://news.bbc.co.uk");
                watch.Start();
                Console.WriteLine("{0} ms", watch.ElapsedMilliseconds);
            }
        }
    }
    

    Prints 880 ms on my PC.

提交回复
热议问题