Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this WebRequest code slow?
    primarykey
    data
    text
    <p>I requested 100 pages that all 404. I wrote</p> <pre><code> { var s = DateTime.Now; for(int i=0; i &lt; 100;i++) DL.CheckExist("http://google.com/lol" + i.ToString() + ".jpg"); var e = DateTime.Now; var d = e-s; d=d; Console.WriteLine(d); } static public bool CheckExist(string url) { HttpWebRequest wreq = null; HttpWebResponse wresp = null; bool ret = false; try { wreq = (HttpWebRequest)WebRequest.Create(url); wreq.KeepAlive = true; wreq.Method = "HEAD"; wresp = (HttpWebResponse)wreq.GetResponse(); ret = true; } catch (System.Net.WebException) { } finally { if (wresp != null) wresp.Close(); } return ret; } </code></pre> <p>Two runs show it takes 00:00:30.7968750 and 00:00:26.8750000. Then i tried firefox and use the following code</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; for(var i=0; i&lt;100; i++) document.write("&lt;img src=http://google.com/lol" + i + ".jpg&gt;&lt;br&gt;"); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Using my comp time and counting it was roughly 4 seconds. 4 seconds is 6.5-7.5faster then my app. I plan to scan through a thousands of files so taking 3.75hours instead of 30mins would be a big problem. How can i make this code faster? I know someone will say firefox caches the images but i want to say 1) it still needs to check the headers from the remote server to see if it has been updated (which is what i want my app to do) 2) I am not receiving the body, my code should only be requesting the header. So, how do i solve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload