Skip to content

Instantly share code, notes, and snippets.

@ym
Created November 22, 2012 19:34
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 ym/4132644 to your computer and use it in GitHub Desktop.
Save ym/4132644 to your computer and use it in GitHub Desktop.
v2ex.com/t/51889
<?php
function test_void () { return false; }
function test_1 ($params = array()) {
if (is_array($params)) {
foreach ($params as $param) {
test_void($param);
}
}
}
function test_2 ($params = array()) {
$params = is_array($params) ? $params : array();
foreach ($params as $param) {
test_void($param);
}
}
function test_item ($function = 'test_void', $times = 100000) {
$time = microtime(true);
for ($i = 0; $i < $times; $i++) {
$function(array(time()));
}
for ($i = 0; $i < $times; $i++) {
$function(time());
}
$time = microtime(true) - $time;
echo "{$function}: {$time}, {$times} \n";
}
test_item('test_1');
test_item('test_2');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment