Optimizing PHP code using ticks

https://www.php.net/manual/en/function.register-tick-function.php

You can compare two ways of coding a script for the same end result by counting the number of ticks it takes to execute each version.

For this you can use register_tick_function() that allows you to execute a certain function at each tick.

For this to work you will need to use the declare function with the tick directive.

https://www.php.net/manual/en/control-structures.declare.php

declare(ticks=1);
$c=0;
// A function called on each tick event
function tick_handler()
{
    global $c;
    $c+=1;
}

register_tick_function('tick_handler');
echo $c.'\n';

Keep in mind that some code might be more efficient than others for the same task due to their underlying C implementation. Or is it stricly equivalent (less tick== always faster)?