Skip to content

Instantly share code, notes, and snippets.

@schigh
Created December 3, 2015 19:39
Show Gist options
  • Save schigh/c053e3d23a5ea23bcdcf to your computer and use it in GitHub Desktop.
Save schigh/c053e3d23a5ea23bcdcf to your computer and use it in GitHub Desktop.
test isset($array[0]) versus count
<?php
$a = [];
$t = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
$sl = isset($a[0]);
}
$t1 = microtime(true);
echo $t1 - $t . chr(10);
$t = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
$sl = count($a);
}
$t1 = microtime(true);
echo $t1 - $t;
// 0.050590991973877
// 0.1452898979187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment