Skip to content

Instantly share code, notes, and snippets.

@jens1o
Last active February 25, 2018 09:59
Show Gist options
  • Save jens1o/621c1307ee0b9d618839211688d46dba to your computer and use it in GitHub Desktop.
Save jens1o/621c1307ee0b9d618839211688d46dba to your computer and use it in GitHub Desktop.
<?php
$emptyArray = [];
$numberArray = range(0, 10000);
$charArray = array_merge(range('a', 'z'), range('A', 'Z'));
foreach([$emptyArray, $numberArray, $charArray] as $array) {
$startTime = microtime(true);
for ($i = 0; $i <= 100000; $i++) {
if (in_array('', $array, true)) {
}
}
$endTime = microtime(true);
echo 'Took ' . round($endTime - $startTime, 2) . 's with strict compare' . PHP_EOL;
$startTime = microtime(true);
for ($i = 0; $i <= 100000; $i++) {
if (in_array('', $array)) {
}
}
$endTime = microtime(true);
echo 'Took ' . round($endTime - $startTime, 2) . 's without strict compare' . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment