<?php
function probe($label, $times, $callback) {
$mem = memory_get_usage();
$start = microtime(true);
$array = $callback($times);
$time = microtime(true) - $start;
$mem = sprintf('%.3f', (memory_get_usage() - $mem) / 1024 / 1024);
return "$label: $time s, $mem MB";
}
$times = 100000;
$run1 = probe('String key', $times, function ($times) {
$a = [];
while ($times-- > 0) {
$a["pagemanagement" . "#" . "staticblocktype" . "#" . $times . "#" . 1] = "test " . $times;
}
return $a;
});
$run2 = probe('CRC32 key', $times, function ($times) {
$a = [];
while ($times-- > 0) {
$a[crc32("pagemanagement" . "#" . "staticblocktype" . "#" . $times . "#" . 1)] = "test " . $times;
}
return $a;
});
$run3 = probe('MD5 key', $times, function ($times) {
$a = [];
while ($times-- > 0) {
$a[md5("pagemanagement" . "#" . "staticblocktype" . "#" . $times . "#" . 1)] = "test " . $times;
}
return $a;
});
$run4 = probe('SHA1 key', $times, function ($times) {
$a = [];
while ($times-- > 0) {
$a[sha1("pagemanagement" . "#" . "staticblocktype" . "#" . $times . "#" . 1)] = "test " . $times;
}
return $a;
});
echo join("<br/>\n", [
$run1,
$run2,
$run3,
$run4,
]);
preferences:
24.18 ms | 410 KiB | 5 Q