Compare performance of two PHP scripts

Asked

Viewed 94 times

3

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

  • eliminated some unnecessary functions;
  • simplified some parts of repeated code into functions;
  • I opted for POO in order to make the script more understandable;
  • ... etc.;

Now how could I check if I really won in terms of performance ? How could I compare the two scribes in this criterio :

  • execution time ;
  • resource consumption on the server;
  • ... etc.;

1 answer

3

Runtime I know answer, now if the performance (performance) is good, taking into account the runtime, I believe it depends more than your algorithm does, make an analysis of complexity and etc.

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 picked up various 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 taking a look at articles on algorithm complexity, which is a very extensive engineering/science subject.

Article on the complexity of algorithms

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 in the network that can help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.