Last active
December 22, 2015 01:39
-
-
Save nikic/6398090 to your computer and use it in GitHub Desktop.
Benchmark for returning large arrays via return_value_ptr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$numElements = 10000000; | |
// Test end() performance | |
$array = [array_fill(0, $numElements, null)]; | |
$startTime = microtime(true); | |
$return = end($array); | |
echo "end(): ", microtime(true) - $startTime, "\n"; | |
unset($array, $return); | |
// Test __call() performance | |
class Foo { | |
public function __call($name, $args) { | |
return $args[0]; | |
} | |
} | |
$array = array_fill(0, $numElements, null); | |
$obj = new Foo; | |
$startTime = microtime(true); | |
$return = $obj->bar($array); | |
echo "__call(): ", microtime(true) - $startTime, "\n"; | |
// RESULTS (before and after) | |
end(): 0.60040688514709 | |
__call(): 0.59498691558838 | |
end(): 0.00011515617370605 | |
__call(): 0.00011706352233887 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment