Last active
February 2, 2016 04:03
-
-
Save joelpittet/2978037a059f0bcd7dd5 to your computer and use it in GitHub Desktop.
Revisions
-
joelpittet revised this gist
Feb 2, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php // Run in your Drupal 8 root with `drush scr perf.php` use Drupal\Component\Utility\SortArray; $data[] = [ -
joelpittet created this gist
Feb 2, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,111 @@ <?php use Drupal\Component\Utility\SortArray; $data[] = [ 0 => [ '#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";