<p>What's the easiest way to profile a PHP script?</p>

<p>I'd love tacking something on that shows me a dump of all function calls and how long they took but I'm also OK with putting something around specific functions.</p>

<p>I tried experimenting with the <a href="http://php.net/microtime" rel="noreferrer">microtime</a> function:</p>

<pre><code>$then = microtime();
myFunc();
$now = microtime();

echo sprintf("Elapsed:  %f", $now-$then);
</code></pre>

<p>but that sometimes gives me negative results.  Plus it's a lot of trouble to sprinkle that all over my code.</p>

I like to use phpDebug for profiling.
http://phpdebug.sourceforge.net/www/index.html
It outputs all time / memory usage for any SQL used as well as all the included files. Obviously, it works best on code that's abstracted.
For function and class profiling I'll just use
```
microtime()
```
+
```
get_memory_usage()
```
+
```
get_peak_memory_usage()
```
.