[ '#type' => 'checkbox', '#title' => 'A', ], 1 => [ '#type' => 'checkbox', '#title' => 'B', ], 2 => [ '#type' => 'checkbox', '#title' => 'C', '#weight' => -1000, ], ]; $data[] = [ 0 => [ '#type' => 'checkbox', '#title' => 'F', ], 1 => [ '#type' => 'checkbox', '#title' => 'E', '#weight' => -500, ], 2 => [ '#type' => 'checkbox', '#title' => 'D', '#weight' => -1000, ], ]; $data[] = [ 0 => [ '#type' => 'checkbox', '#title' => 'H', '#weight' => -1000, ], 1 => [ '#type' => 'checkbox', '#title' => 'I', '#weight' => 500, ], 2 => [ '#type' => 'checkbox', '#title' => 'G', '#weight' => -500 ], ]; $data[] = [ 0 => [ '#type' => 'checkbox', '#title' => 'A', '#weight' => 0, ], 1 => [ '#type' => 'checkbox', '#title' => 'A', '#weight' => 0, ], 2 => [ '#type' => 'checkbox', '#title' => 'A', '#weight' => 0, ], ]; $alpha = []; foreach (range('a', 'z') as $letter) { $alpha[] = [ '#type' => 'checkbox', '#title' => $letter, '#weight' => 0, ]; } $data[] = $alpha; $numeric = []; foreach (range(1, 10000) as $num) { $numeric[] = [ '#type' => 'checkbox', '#title' => 'A', '#weight' => $num, ]; } $data[] = $numeric; // Run these separately to avoid garbagec collection or other PHP interference. // $start = microtime(TRUE); // foreach ($data as $test_data) { // SortArray::suasort($test_data, ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']); // SortArray::suasort($test_data, ['Drupal\Component\Utility\SortArray', 'sortByTitleProperty']); // } // print 'SortArray::suasort: ' . round(microtime(TRUE) - $start, 5) . " seconds\n"; // Run these separately to avoid garbagec collection or other PHP interference. $start = microtime(TRUE); foreach ($data as $test_data) { uasort($test_data, ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']); uasort($test_data, ['Drupal\Component\Utility\SortArray', 'sortByTitleProperty']); } print 'uasort: ' . round(microtime(TRUE) - $start, 5) . " seconds\n";