﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on How to get REALLY fast benchmarks</title><description>Magesh,
  
KAE figured that out :-)
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment21</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment21</guid><pubDate>Wed, 28 Apr 2010 10:08:03 GMT</pubDate></item><item><title>Magesh commented on How to get REALLY fast benchmarks</title><description>Would you care to post the solution?
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment20</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment20</guid><pubDate>Wed, 28 Apr 2010 09:19:31 GMT</pubDate></item><item><title>Gavin commented on How to get REALLY fast benchmarks</title><description>I would use DirectoryInfo instead of Directory to get the file listing. It does less security checks when combined with FileInfo.OpenText it should speed the process when processing a significant number of files ... 
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment19</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment19</guid><pubDate>Tue, 27 Apr 2010 08:48:40 GMT</pubDate></item><item><title>Steve Py commented on How to get REALLY fast benchmarks</title><description>I'd say it's the missing requestStream.Close within the loop. My guess would be that the Close operation would block the thread until the upload was complete so without it, (aside from the risk of running out of connections) your timer wouldn't reflect the actual upload performance. Hence, a false report of smashing performance.
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment18</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment18</guid><pubDate>Tue, 27 Apr 2010 07:30:35 GMT</pubDate></item><item><title>meisinger commented on How to get REALLY fast benchmarks</title><description>you have to either consume or close the ResponseStream 
  
the very least that you have to do is call GetResponse().Close()
  
  
the "fatal flaw" being that you are not closing the underlying HTTP connection
  
at some point in time you are going to run out of available connections and be blocked waiting for an HTTP connection to timeout
  
  
testing and even "production" running code will work given a small number of files
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment17</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment17</guid><pubDate>Mon, 26 Apr 2010 16:56:32 GMT</pubDate></item><item><title>Leyu Sisay commented on How to get REALLY fast benchmarks</title><description>@Justin I think what you said above is correct, but when using Directory.GetFiles the order of the returned file names is not guaranteed, so using OrderBy is necessary.
  
  
  
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment16</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment16</guid><pubDate>Mon, 26 Apr 2010 08:02:25 GMT</pubDate></item><item><title>Manu commented on How to get REALLY fast benchmarks</title><description>You must call the Stream.Close method to close the stream and release the connection for reuse. Failure to close the stream causes your application to run out of connections.
  
  
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment15</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment15</guid><pubDate>Mon, 26 Apr 2010 07:51:58 GMT</pubDate></item><item><title>Justin commented on How to get REALLY fast benchmarks</title><description>The statement "Directory.GetFiles("Docs", searchPattern).OrderBy(x=&gt;x)"
  
  
By default, the GetFiles would usually return the files within the alphabetical order. Also, "GetFiles" is a blocking operation waiting for the entire array to be built up.
  
  
Therefore, the Stopwatch would only start measuring after the more expensive operations began. This would also only measure the very last cycle in the foreach loop... not the overall response time of the ENTIRE method.
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment14</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment14</guid><pubDate>Mon, 26 Apr 2010 06:36:15 GMT</pubDate></item><item><title>Magesh commented on How to get REALLY fast benchmarks</title><description>The http request is not submitted until the "GetResponse()" method of the HttpWebRequest class is invoked.  The code in the blog post writes the data to the local stream and discards it without initiating the actual web request.
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment13</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment13</guid><pubDate>Mon, 26 Apr 2010 06:13:43 GMT</pubDate></item><item><title>Aaron Carlson commented on How to get REALLY fast benchmarks</title><description>You never hit Stop on the stop watch.
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment12</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment12</guid><pubDate>Sun, 25 Apr 2010 17:34:22 GMT</pubDate></item><item><title>Shane commented on How to get REALLY fast benchmarks</title><description>You initialized your variable in the for loop so technically you are measuring only the last request and none of the file access or any of the other requests.
  
  
var sp = Stopwatch.StartNew();
  
  
 foreach (var file in Directory.GetFiles("Docs", searchPattern).OrderBy(x=&gt;x))
  
    {
  
        //var sp = Stopwatch.StartNew();
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment11</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment11</guid><pubDate>Sun, 25 Apr 2010 15:10:38 GMT</pubDate></item><item><title>manningj commented on How to get REALLY fast benchmarks</title><description>Haven't tested it much (would definitely only work for sync, for instance), but:
  
  
    public class TimedWebClient : WebClient
  
    {
  
        public TimeSpan LastResponseTime { get; private set; }
  
        protected override WebResponse GetWebResponse(WebRequest request)
  
        {
  
            var stopWatch = Stopwatch.StartNew();
  
            var response = base.GetWebResponse(request);
  
            this.LastResponseTime = stopWatch.Elapsed;
  
  
            return response;
  
        }
  
    }
  
  
  
consume like:
  
  
        static void Main(string[] args)
  
        {
  
            var webClient = new TimedWebClient();
  
            var url = "
[http://www.google.com](http://www.google.com)";
  
            webClient.DownloadString(url);
  
            Console.WriteLine("Downloading {0} took {1} ms", url, webClient.LastResponseTime.TotalMilliseconds);
  
            Console.ReadLine();
  
        }
  
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment10</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment10</guid><pubDate>Sun, 25 Apr 2010 13:18:27 GMT</pubDate></item><item><title>Ken Egozi commented on How to get REALLY fast benchmarks</title><description>As people pointed out, GetResponse actually fire the HTTP request.
  
  
@Leonard - you should not reuse HttpWebRequest instances. Calling consecutive calls for GetResponse() will return a cached result of the first call, without re-issuing an HTTP request.
  
  
  
btw, I'd use WebClient as long as you do not need to mingle too much with the returned Response in term of headers, certificates etc.
  
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment9</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment9</guid><pubDate>Sun, 25 Apr 2010 11:36:28 GMT</pubDate></item><item><title>leonard commented on How to get REALLY fast benchmarks</title><description>Should this httpWebRequest be created in the loop?
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment8</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment8</guid><pubDate>Sun, 25 Apr 2010 10:43:55 GMT</pubDate></item><item><title>Merill Fernando commented on How to get REALLY fast benchmarks</title><description>Marco was right, you need to call GetResponse to perform the upload. If not, nothing is going to be uploaded.
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment7</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment7</guid><pubDate>Sun, 25 Apr 2010 10:23:26 GMT</pubDate></item><item><title>Sam commented on How to get REALLY fast benchmarks</title><description>If your trying to benchmark the overall performance of loading all the documents in the directory, then I'm guessing that the 'var sp = Stopwatch.StartNew();' should be outside the foreach loop.
  
  
Otherwise the elapsed time is going to get reset on each iteration.
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment6</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment6</guid><pubDate>Sun, 25 Apr 2010 10:12:14 GMT</pubDate></item><item><title>Philipp commented on How to get REALLY fast benchmarks</title><description>Another try (my last comment was flagged as spam): It might be that the server doesn't get the request until you invoke GetResponse due to buffering.
  
  
Not related to the performance issue: Stopping the Stopwatch might be a good idea, or directly encapsulating the whole measurement. I did something similar here:
  
[http://tinyurl.com/39op9j7](http://tinyurl.com/39op9j7)</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment5</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment5</guid><pubDate>Sun, 25 Apr 2010 10:04:45 GMT</pubDate></item><item><title>Marco De Sanctis commented on How to get REALLY fast benchmarks</title><description>Uh oh... nope sorry, made a mistake.. The request is within a using block, so you're actually flushing it! It's Sunday morning here in Italy, and my brain started in Safe Mode today, LOL ;-)
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment4</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment4</guid><pubDate>Sun, 25 Apr 2010 09:41:36 GMT</pubDate></item><item><title>Richard Dingwall commented on How to get REALLY fast benchmarks</title><description>Forgot to specify HttpWebRequest.ContentLength before writing to the request stream?
  
  
[msdn.microsoft.com/.../...quest.contentlength.aspx](http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.contentlength.aspx)</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment3</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment3</guid><pubDate>Sun, 25 Apr 2010 09:30:17 GMT</pubDate></item><item><title>Demis Bellot commented on How to get REALLY fast benchmarks</title><description>What @Marco said, plus you're not checking the response so you don't know if the request was successful.
  
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment2</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment2</guid><pubDate>Sun, 25 Apr 2010 09:28:59 GMT</pubDate></item><item><title>Marco De Sanctis commented on How to get REALLY fast benchmarks</title><description>Uhm... perhaps you're not flushing the request stream and thus you're only measuring how long does it take to write data onto the stream's internal buffer?
</description><link>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment1</link><guid>http://ayende.com/4471/how-to-get-really-fast-benchmarks#comment1</guid><pubDate>Sun, 25 Apr 2010 09:17:50 GMT</pubDate></item></channel></rss>