0

When we have to return only one value parsed by sscanf / fscanf, should we assign a list of one variable or use optional assigned values?

E.G.

list($number) = fscanf($handle, "%d\n")

or

fscanf($handle, "%d\n", $number)

Is there any difference in execution speed of these expressions?

1 Answers1

0

Just benchmark your two ways with a script like this:

<?php
function micro_time() {
    $temp = explode(" ", microtime());
    return bcadd($temp[0], $temp[1], 6);
}

$time_start = micro_time();

for ($i=0; $i<100; $i++) {

    // the code you want to benchmark

}

$time_stop = micro_time();

$time_overall = bcsub($time_stop, $time_start, 6);
echo "Execution time - $time_overall Seconds";
?>
Frederick Behrends
  • 3,075
  • 23
  • 47