Skip to content

Instantly share code, notes, and snippets.

@nikic
Last active December 22, 2015 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikic/6398090 to your computer and use it in GitHub Desktop.
Save nikic/6398090 to your computer and use it in GitHub Desktop.
Benchmark for returning large arrays via return_value_ptr
<?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