Skip to content

Instantly share code, notes, and snippets.

@gallir
Created January 22, 2015 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gallir/8e43f84b370df78ef9e5 to your computer and use it in GitHub Desktop.
Save gallir/8e43f84b370df78ef9e5 to your computer and use it in GitHub Desktop.
test de hash y arrays
<?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