-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.php
More file actions
40 lines (31 loc) · 927 Bytes
/
sort.php
File metadata and controls
40 lines (31 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
use Melicerte\Sorts\AlgorithmFactory;
use Melicerte\Sorts\Helper\ArrayHelper;
use Melicerte\Sorts\Helper\Timer;
require_once './vendor/autoload.php';
// Read parameters
$algorithmName = $argv[1];
$arraySize = $argv[2];
$display = isset($argv[3]) && $argv[3] === 'display';
// Generate array
echo "Generating array with $arraySize elements ...";
$array = ArrayHelper::generateArray($arraySize);
echo " done\r\n";
// Display initial array
if ($display) {
ArrayHelper::displayArray($array);
}
// Get algorithm
$algorithm = AlgorithmFactory::getAlgorithm($algorithmName);
echo 'Sort array using '.$algorithm->getName()." algorithm. Go !\r\n";
// Sort !
$timer = new Timer();
$timer->start();
$sortedArray = $algorithm->sort($array);
$timer->end();
// Display sorted array
if ($display) {
ArrayHelper::displayArray($sortedArray);
}
// Display execution time
echo 'Execution time = '.$timer->getTime()."s\r\n";