Using functions as parameters for other functions is slower?

1

I'm getting information from a site that generates content in JSON format and there was a question about using functions as a parameter to other functions, does this slow down the application? and if so, how to know?

Example:

$requestUrl = 'BlaBla.com';
$pageContent = json_decode(file_get_contents($requestUrl), true);

OR

$pageContent = file_get_contents($requestUrl);
$decodeContent = json_decode($pageContent, true);
    
asked by anonymous 22.12.2014 / 07:50

1 answer

2

No. In your example the time difference is derisory, do not worry about it. I believe that a significant difference will only be noticed in recursive functions that abuse function calls. If you really want to test this, use the code below.

$start = microtime(true);

$requestUrl = 'BlaBla.com';
$pageContent = json_decode(file_get_contents($requestUrl), true);

$end = microtime(true);
$time = number_format(($end - $start), 2);

echo 'Tempo de execução ', $time, ' segundos';
    
22.12.2014 / 12:28