Name | random | sorted | rsorted |
---|---|---|---|
straightInsertion | 7.48131 | 0.0095 | 13.68925 |
binaryInsertion | 5.46446 | 0.05528 | 10.8473 |
straightSelection | 21.2452 | 21.34226 | 25.2773 |
bubbleSort | 22.76245 | 12.45991 | 31.98982 |
shakerSort | 18.75352 | 0.00392 | 32.69624 |
heapSort | 0.11843 | 0.12559 | 0.11432 |
quickSortRecursive | 11.91182 | 6.7423 | 6.43074 |
quickSortRecursiveNew | 7.41534 | 7.45058 | 7.38413 |
quickSort | 0.05555 | 0.02845 | 0.03096 |
sort | 0.00869 | 0.00467 | 0.005 |
Different sort algorithms have advantage in certain conditions. So this benchmark can't show the advantage of all of them.
Function quickSortRecursive receives an array as parameter and then creates new static array for the recursion calls. quickSortRecursiveNew uses global array and it sorts random array faster then quickSortRecursive.
The iterative version of quick sort is more then 100 faster then recursive one!!!
The last function is PHP native function for sorting arrays. It so fast because it isn't run through PHP interpreter. Use PHP native functions, they are a lot faster.
The source of benchmark and all of the functions can be found here.
No comments:
Post a Comment