{"id":23,"date":"2007-07-24T10:41:34","date_gmt":"2007-07-24T14:41:34","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/andrew\/2007\/07\/24\/including-benchmarks\/"},"modified":"2007-07-24T10:41:34","modified_gmt":"2007-07-24T14:41:34","slug":"including-benchmarks","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/andrew\/2007\/07\/24\/including-benchmarks\/","title":{"rendered":"Including benchmarks"},"content":{"rendered":"<p>As part of the namespace discussion, the performance difference between including multiple files and concatenating those files into a single file, mainly because of the <a href=\"http:\/\/blogs.n1zyy.com\/andrew\/2007\/07\/13\/namespaces\/\">aforementioned<\/a> limitation.<\/p>\n<p>In response to an argument for concatenation, <a href=\"http:\/\/lerdorf.com\/bio.php\">Rasmus Lerdorf<\/a> (original author of PHP) said:<\/p>\n<blockquote><p>Note that what you are saving by combining the files into one is just a single stat syscall per file.  And that can be alleviated by setting apc.stat=0 in your config.  That of course means you need to restart your server or flush your cache whenever you want to update the files. In apc.stat=0 mode you gain nothing by merging all the files.<\/p><\/blockquote>\n<p>Now, I&#8217;d always theorized that concatenation could a present measurable performance increase, so I was a little muffed by this statement. Consequently, I ventured forth to prove this out.<\/p>\n<h2>Setup<\/h2>\n<p>First, I generated 100 files each containing a single class. The files and classes were named consecutively, 1-100. I then created one script that dynamically included each file, another that statically included each file, and one that contained all of the files concatenated together. I used <a href=\"http:\/\/httpd.apache.org\/docs\/2.0\/programs\/ab.html\">Apache Bench<\/a> and had <a href=\"http:\/\/php.net\/apc\">APC<\/a> enabled. I ran one set of tests with <code>apc.stat=0<\/code> and one with <code>apc.stat=1<\/code>. The tests were run on a AMD Sempron 2600+ with 512MB of RAM, running Apache 2.0.58 with mpm-prefork and PHP 5.1.6.<\/p>\n<h2>Results<\/h2>\n<p>I was a little surprised by the results. Because they were better than I&#8217;d ever theorized: even with <code>apc.stat=0<\/code>, the concatenated file request times were less than half those of the static list.<\/p>\n<h4>Dynamic<\/h4>\n<pre>Requests per second:    247.86 [#\/sec] (mean)\nTime per request:       40.346 [ms] (mean)<\/pre>\n<h4>Static<\/h4>\n<pre>Requests per second:    279.86 [#\/sec] (mean)\nTime per request:       35.732 [ms] (mean)<\/pre>\n<h4>Concatenated<\/h4>\n<pre>Requests per second:    605.07 [#\/sec] (mean)\nTime per request:       16.527 [ms] (mean)<\/pre>\n<p>Also of note: the dynamic includes didn&#8217;t really lose by much to the static includes. That should make people using <code>__autoload<\/code> (like me, at work) happy (it does).<\/p>\n<p>Apparently, there&#8217;s still some performance to be gained by concatenating your libraries into a single file, even with a byte-code cache. Now, granted, you may not always include 100 files, or your entire library. However, by analyzing your usage patterns, you could always create a single file containing the classes you use the most, and leave those only occasionally used to your autoload implementation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of the namespace discussion, the performance difference between including multiple files and concatenating those files into a single file, mainly because of the aforementioned limitation. In response to an argument for concatenation, Rasmus Lerdorf (original author of PHP) said: Note that what you are saving by combining the files into one is just [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/andrew\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}