<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function InsertionSort($data, $L)
{
$time_start = microtime_float();
for ($i = 1; $i < $L; $i++) {
for ($j = $i; $j > 0 && $data[$j] < $data[$j - 1]; $j--) {
list($data[$j], $data[$j - 1]) = [$data[$j - 1], $data[$j]];
}
}
$time_end = microtime_float();
echo "InsertionSort - Time:" . ($time_end - $time_start) . "s" . "<br>";
return $data;
}
function main()
{
$number = [];
for ($i = 0; $i < 10000; $i++) {
$number[] = rand(0, 1000000000);
}
InsertionSort($number, count($number));
}
main();