<div dir="ltr">Hello!<div><br></div><div>Underneath the hood, they are both using the same function to actually serve the file. There are a few reasons why serveDirectory might appear to be faster.</div><div><br></div><div>The first thing to double check is that both serveDirectory and serveFile are returning 200 OK, and not 404. You want to confirm that the file really is being transferred in both cases.</div><div><br></div><div>Given that favicon.ico is likely a small file, the time spent processing requests could be dominated by some other seemingly insignificant factor. Since serveDirectory is listed first, it is going to have a slight advantage, because the routes are tried in order. If you switch the order and list serveFile first do you see any change in performance?</div><div><br></div><div>Additionally, in this code you could get away with using 'dir' instead of 'dirs' since you do not have any '/' in the path. Because 'dirs' has to look for the '/', it is going to take longer to search 'favicon.ico' than 'hehe' -- which would also give a slightly advantage to the serveDirectory branch.</div><div><br></div><div>You are correct in expecting that serveFile should be faster than serveDirectory since it is supposed to do less. But microbenchmarks like this can easily be dominated by unrelated factors. </div><div><br></div><div>- jeremy</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 23, 2015 at 10:09 AM, Semen Trygubenko / Семен Тригубенко <span dir="ltr"><<a href="mailto:semen@trygub.com" target="_blank">semen@trygub.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all,<br>
<br>
I've ran a simple benchmark where two serve functions<br>
were side-by-side in an msum and looked like<br>
<br>
dirs "hehe"     $ serveDirectory DisableBrowsing [] "/hehe"<br>
dirs "favicon.ico" $ serveFile (asContentType "image/x-icon") "favicon.ico"<br>
<br>
"hehe" directory also contained file "favicon.ico".<br>
<br>
This is happstack server version 7.3.9.<br>
<br>
I've been hammering it with ab and confirmed this puzzling result:<br>
it seems that serveFile route is approximately<br>
two orders of magnitude slower than serveDirectory route...<br>
<br>
Will be grateful for any clues as to what I'm doing wrong!<br>
<br>
Thanks,<br>
S.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Семен Тригубенко <a href="http://trygub.com" target="_blank">http://trygub.com</a><br>
</font></span><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>