PHP Sorting Algorithms Benchmarker: Benchmark sorting arrays with different algorithms

Recommend this page to a friend!
  Info   View files Documentation   View files View files (15)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2021-05-11 (Yesterday) RSS 2.0 feedNot enough user ratingsTotal: 64 This week: 38All time: 9,851 This week: 4Up
Version License PHP version Categories
sorter 1.1.3GNU General Publi...7Algorithms, PHP 5, Data types
Description Author

This package can benchmark sorting arrays with different algorithms.

It provides several classes that can sort arrays using several different algorithms like for instance: PHP native sort, bubble, comb, gnome, heap, MatosGoulart, quick and shell.

An additional class can also measure the time each algorithm take sort the arrays and stores the results in a class variable that can be inspected and displayed to compare the results.

Innovation Award
PHP Programming Innovation award nominee
April 2021
Nominee
Vote
There are many ways to sort arrays, so they can present the data inside them in a way that is more convenient for the kind of processing that applications need to perform.

This package can help developers determining what can be the best method to sort arrays by testing each of the supported method by the package.

Then it can return information about the speed of processing of each of the methods to help developers deciding which is the best method for their purposes.

Manuel Lemos
Picture of Carlos Artur Curvelo da Matos
  Performance   Level  
Name: Carlos Artur Curvelo da ... is available for providing paid consulting. Contact Carlos Artur Curvelo da ... .
Classes: 14 packages by
Country: Portugal Portugal
Age: 43
All time rank: 382443 in Portugal Portugal
Week rank: 3 Up1 in Portugal Portugal Up
Innovation award
Innovation award
Nominee: 7x

 

Details

Sorter

Collection of sorting algorithms implemented in PHP classes. Also, a benchmarking class for doing performance tests using any array and passing it through all available sorting algorithms. At this moment, this library can sort arrays in the following sorting algorithms:

  • PHP sort()
  • Quick Sorting
  • Bubble Sorting
  • Heap Sorting
  • Gnome Sorting
  • Shell Sorting
  • Comb Sorting
  • Insertion Sorting
  • Merge Sorting
  • Selection Sorting
  • Matos-Goulart Simple Sorting (recently created by myself)

Matos-Goulart Simple Sorting Algorithm 2021 by Carlos Artur C. S. Matos is licensed under Attribution 4.0 International .

All sorting algorithms can be applied to any array of integers using the respective static method. Also, using the class Benchmark() the developer can perform all sorting methods at once, and get a var_dump() of the benchmark times in seconds. Also, we compare all sort methods in the becnhmark with PHP's native sort() function, as reference.

Usage

require __DIR__ . '/vendor/autoload.php';

$matos = \Sorter\MatosGoulart::sort([2, 6, 78, 11, 23, 1, 4, 1902, 192]);

/*
Results in:

array(9) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(4)
  [3]=>
  int(6)
  [4]=>
  int(11)
  [5]=>
  int(23)
  [6]=>
  int(78)
  [7]=>
  int(192)
  [8]=>
  int(1902)
}

*/

Obviously, all other sorting methods will result in the same response array - as the main objective of this library is to realize benchmarking tests amongst all possible algorithms, rather than sorting numbers itself. All details on the algorithms and some pseudocode for implementations in other programming languages can be found on each class' docblock comments.

Benchmark

Also, this library has a Benchmark class, which can be used to subject an array to all sorting methods, and then return benchmark times for each of the sorting algorithms. As simple as follows:

use Sorter\Benchmark;

require __DIR__ . '/vendor/autoload.php';



$ro = new Benchmark([2, 4, 1, 23, 32, 11, 45, 67, 5, 233455, 344 , 7, 24, 67, 1111111, 111, 34, 2344]);
$ro->get();

/*
RESULTS IN:

array(8) {
  ["quick"]=>
  string(14) "0.127814000000"
  ["bubble"]=>
  string(14) "0.033583000000"
  ["heap"]=>
  string(14) "0.035445000000"
  ["gnome"]=>
  string(14) "0.015428000000"
  ["shell"]=>
  string(14) "0.012064000000"
  ["comb"]=>
  string(14) "0.000609000000"
  ["insertion"]=>
  string(14) "0.015089000000"
  ["matos_goulart"]=>
  string(14) "0.011882000000"
}
*/
  Files folder image Files  
File Role Description
Files folder imagesrc (12 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Benchmark.php Class Class source
  Plain text file Bubble.php Class Class source
  Plain text file Comb.php Class Class source
  Plain text file Gnome.php Class Class source
  Plain text file Heap.php Class Class source
  Plain text file Insertion.php Class Class source
  Plain text file MatosGoulart.php Class Class source
  Plain text file Merge.php Class Class source
  Plain text file Quick.php Class Class source
  Plain text file Selection.php Class Class source
  Plain text file Shell.php Class Class source
  Plain text file SorterAbstract.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:64
This week:38
All time:9,851
This week:4Up

For more information send a message to info at phpclasses dot org.