Skip to content

Instantly share code, notes, and snippets.

@schigh
Last active December 3, 2015 19:38
Show Gist options
  • Save schigh/db0bf35ee8d971e1f2ef to your computer and use it in GitHub Desktop.
Save schigh/db0bf35ee8d971e1f2ef to your computer and use it in GitHub Desktop.
strlen versus isset($string{14})
<?php
$a = <<<EOT
hkjahkdjhakdjhask jdha ksjdhakjsdhkajhsdkjahs dkajh sdkajhs dkah sdkajh sdoqi oegpwgpsgsldjglsj dlkjs lgkjs ldkgjls
lsk dglks gljs ldgjsldjg lsdjg lsjg lskjglksdjglskjdglksdjg lskdjglksjdglksj dfsf lskdjfklsjdf lksjdflkjslkjkd dkdk
EOT;
$t = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
$sl = isset($a{14});
}
$t1 = microtime(true);
echo $t1 - $t . chr(10);
$t = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
$sl = strlen($a);
}
$t1 = microtime(true);
echo $t1 - $t;
// 0.048465967178345
// 0.12918090820312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment