Created
January 22, 2015 23:42
-
-
Save gallir/8e43f84b370df78ef9e5 to your computer and use it in GitHub Desktop.
test de hash y arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = array(); | |
$b = array(); | |
for ($i = 0; $i <50; $i+=1) { | |
$a[$i] = $i; | |
$b[] = $i; | |
} | |
$start = microtime(true); | |
for ($j=0; $j <500000; $j++) { | |
for ($i = 0; $i <50; $i+=1) { | |
isset($a[$i]); | |
} | |
} | |
$end = microtime(true) - $start; | |
echo "1: $end\n"; | |
$start = microtime(true); | |
for ($j=0; $j <500000; $j++) { | |
for ($i = 0; $i <50; $i+=1) { | |
in_array($i, $b); | |
} | |
} | |
$end = microtime(true) - $start; | |
echo "2: $end\n"; | |
/* Nota: con enteros, si se usa string como clave es una tres veces más lento el hash */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment