Compare performance of two PHP script

3

I worked on a PHP script, later I found it too complex and cumbersome and felt the need to simplify it.

  • I've deleted some unnecessary functions;
  • I have simplified some parts of the code repeated in functions;
  • I chose POO to make the script more understandable;
  • ... etc;

Now how could I check to see if I actually won in terms of performance ? How could you compare the two escript in this criterion:

  • runtime;
  • resource consumption on the server;
  • ... etc;
asked by anonymous 17.12.2016 / 16:39

1 answer

3

Runtime I know how to respond, now if the performance is good, taking into consideration the runtime, I believe it depends more on what your algorithm does, do a complexity analysis and so on.

At the beginning of the algorithm:

$time_start = microtime(true); // Inicializa a variável $time no inicio do seu script
.
.
{seu código aqui}
.
.
$time_end = microtime(true);
$time = $time_end - $time_start;
echo $time; // Te traz o tempo em milissegundos de execução do algorítimo

In a script that took several data from another server, it brought me the runtime of 59s - 65s for example.

Performance can be measured by the amount of loops , number of recursive functions, number of similar functions that could be grouped, I believe it is worth reading articles on algorithm complexity, which is an engineering / computer science.

Article about algorithm complexity

Resource consumption, there are internal commands on a server (linux, windows, among others) that can be used to analyze the amount of resources consumed during the execution time of a script, unfortunately I do not have much experience in the subject, but there are some questions here on the network that can help.

    
17.12.2016 / 16:52