How to measure the speed of code written in PHP?

Posted by Editorial Staff | Updated on

IF you want to measure the speed of code written in PHP? The quite “naïve” one is using microtime(true) tobefore and after a portion of code, to get how much time has passed during its execution; other answers said that and gave examples already, so I won”t say much more.

This is a nice solution if you want to benchmark a couple of instructions ; like compare two types of functions, for instance — it’s better if done thousands of times, to make sure any “perturbating element” is averaged.

Something like this, so, if you want to know how long it take to serialize an array :


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers