I wonder if wrapper function in php executes at the same speed as bare function. Is php engine optimized to detect these cases? Where can I read more about it?
I tried following, and it seems to return generally the same numbers both for test
and test_wrapper
<?php
function test() {
return 1;
}
function test_wrapper() {
return test();
}
$time_start = microtime(true);
test_wrapper();
$time_end = microtime(true);
$execution_time = ($time_end - $time_start) / 60;
echo '<b>Total Execution Time:</b> '.$execution_time.' Mins';
I've tested this code and came to the conclusion there is not much difference.
$b = new \Benchmark(10000000, 1);
function test() {
return 1;
}
function test_wrapper() {
return test();
}
$b->register('test', function(){
test();
});
$b->register('test_wrapper', function(){
test_wrapper();
});
print_r($b->start());
Using my own library these are the results:
Array
(
[stats] => Array
(
[phpversion] => 7.1.2
[itterations] => 20000000
[duration] => 5.7083499431
[fastest] => test
[slowest] => test_wrapper
)
[results] => Array
(
[0] => Array
(
[name] => test
[time] => 2.7408945560
[average] => 0.0000002741
[speed] => 7.63%
)
[1] => Array
(
[name] => test_wrapper
[time] => 2.9674553871
[average] => 0.0000002967
[speed] => 0.00%
)
)
)