<p>How can you determine the performance consequences of your PHP code if you are not familiar with the internals? Are there ways to figure out how your code is being executed (besides simply load testing it)? I am looking for things like memory usage, the execution time for algorithms.</p>

<p>Perhaps Joel would say, "learn C, then read the internals", but I really don't have time to learn C right now (though I'd love to, actually). </p>

[{'answer_id': 51045, 'author': 'Jordi Bunster', 'author_id': 4272, 'author_profile': 'https://Stackoverflow.com/users/4272', 'pm_score': 3, 'selected': True, 'text': '<p>Use the <a href="http://www.xdebug.org/" rel="nofollow noreferrer">Xdebug</a> extension to profile PHP code.</p>\n'}, {'answer_id': 51376, 'author': 'reefnet_alex', 'author_id': 2745, 'author_profile': 'https://Stackoverflow.com/users/2745', 'pm_score': 2, 'selected': False, 'text': '<p>If you\'re not familiar with valgrind or similar, then to add to @Jordi Bunster\'s answer...</p>\n\n<p>When you\'ve had profiling on in Xdebug, you can open the dumped profile files in KCacheGrind or WinCacheGrind to get a graphical view of what is taking the time in your code. </p>\n\n<p>Fortunately the xdebug documentation also explains this in detail as well as how to interpret the results: <a href="http://xdebug.org/docs/profiler" rel="nofollow noreferrer">http://xdebug.org/docs/profiler</a></p>\n'}, {'answer_id': 54324, 'author': 'Gary Richardson', 'author_id': 2506, 'author_profile': 'https://Stackoverflow.com/users/2506', 'pm_score': 0, 'selected': False, 'text': '<p>Even if you are familiar with the internals, you should still load test your assumptions. I like to use the <a href="http://pear.php.net/package/Benchmark" rel="nofollow noreferrer">PEAR Benchmark</a> package to compare different code.</p>\n\n<p>If you can isolate your code, you can keep your load testing simple. A typical technique is to run each option some number of times and see which one is faster. For example, if you have a class, you can write a test case and that puts it through it\'s paces and run it several times.</p>\n'}, {'answer_id': 2227253, 'author': 'StasM', 'author_id': 214196, 'author_profile': 'https://Stackoverflow.com/users/214196', 'pm_score': 0, 'selected': False, 'text': '<p>You can use low-level approach such as sticking <code>microtime()</code> and <code>memory_get_usage()</code> calls into the code or you can use one of existing profiling solutions:</p>\n\n<ol>\n<li><a href="http://xdebug.org/" rel="nofollow noreferrer">Xdebug</a> (free, opensource)</li>\n<li><a href="http://www.zend.com/en/products/studio/features#debug" rel="nofollow noreferrer">Zend Studio/Debugger</a> profiling (commercial)</li>\n<li><a href="http://www.zend.com/products/server/zend-server-code-tracing" rel="nofollow noreferrer">Zend Server Code Tracing</a> (commercial)</li>\n<li><a href="http://mirror.facebook.net/facebook/xhprof/doc.html" rel="nofollow noreferrer">xhprof</a> (free, opensource)</li>\n</ol>\n\n<p>As usual, commercial tools have nice GUIs and pretty pictures, but cost money, free ones are free, but you\'d probably have to invest a bit more time. </p>\n\n<p>Also, PHP CGI binary has a benchmark mode with <code>-T</code> option, you many try running <code>php-cgi -T 100 yourscript.php</code> to do a poor man\'s benchmark. </p>\n'}, {'answer_id': 3172246, 'author': 'Ira Baxter', 'author_id': 120163, 'author_profile': 'https://Stackoverflow.com/users/120163', 'pm_score': 0, 'selected': False, 'text': '<p>See <a href="http://www.semanticdesigns.com/Products/Profilers/PHPProfiler.html" rel="nofollow noreferrer">SD PHP Profiler</a> for a tool that can show you graphically where your PHP applications spends its time.</p>\n'}]
['https://Stackoverflow.com/questions/51017', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/577/']