kphp
kphp copied to clipboard
shuffle optimization on vectors
few changes
-
shuffle
returnstrue
as in php - reset keys even with 1 element array
$x = [2 => 1];
shuffle($x);
var_dump($x);
// kphp master: [2 => 1]
// php: [0 => 1]
- don't allocate new memory if array is already vector
$x = range(0, 100000);
$start = microtime(true);
for ($i = 0; $i < 1000; $i++) {
shuffle($x);
}
var_dump(microtime(true) - $start);
// this branch: 1.5391621589661
// master: 2.5984324812889