kphp icon indicating copy to clipboard operation
kphp copied to clipboard

shuffle optimization on vectors

Open vajexal opened this issue 3 years ago • 0 comments

few changes

  • shuffle returns true 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

vajexal avatar Feb 20 '22 18:02 vajexal