Exemplo n.º 1
0
simpleudcall();
$t = end_test($t, "simpleudcall");
mandel();
$t = end_test($t, "mandel");
mandel2();
$t = end_test($t, "mandel2");
ackermann(7);
$t = end_test($t, "ackermann(7)");
ary(50000);
$t = end_test($t, "ary(50000)");
ary2(50000);
$t = end_test($t, "ary2(50000)");
ary3(2000);
$t = end_test($t, "ary3(2000)");
fibo(30);
$t = end_test($t, "fibo(30)");
hash1(50000);
$t = end_test($t, "hash1(50000)");
hash2(500);
$t = end_test($t, "hash2(500)");
heapsort(20000);
$t = end_test($t, "heapsort(20000)");
matrix(20);
$t = end_test($t, "matrix(20)");
nestedloop(12);
$t = end_test($t, "nestedloop(12)");
sieve(30);
$t = end_test($t, "sieve(30)");
strcat(200000);
$t = end_test($t, "strcat(200000)");
total($t0, "Total");
Exemplo n.º 2
0
        $i = $l;
        $j = $l << 1;
        while ($j <= $ir) {
            if ($j < $ir && $ra[$j] < $ra[$j + 1]) {
                $j++;
            }
            if ($rra < $ra[$j]) {
                $ra[$i] = $ra[$j];
                $j += $i = $j;
            } else {
                $j = $ir + 1;
            }
        }
        $ra[$i] = $rra;
    }
}
function heapsort($N)
{
    global $LAST;
    define("IM", 139968);
    define("IA", 3877);
    define("IC", 29573);
    $LAST = 42;
    for ($i = 1; $i <= $N; $i++) {
        $ary[$i] = gen_random(1);
    }
    heapsort_r($N, $ary);
    printf("%.10f\n", $ary[$N]);
}
heapsort(7);
Exemplo n.º 3
0
                $ra[1] = $rra;
                return;
            }
        }
        $i = $l;
        $j = $l << 1;
        while ($j <= $ir) {
            if ($j < $ir && $ra[$j] < $ra[$j + 1]) {
                $j++;
            }
            if ($rra < $ra[$j]) {
                $ra[$i] = $ra[$j];
                $j += $i = $j;
            } else {
                $j = $ir + 1;
            }
        }
        $ra[$i] = $rra;
    }
}
$N = $argc == 2 ? $argv[1] : 10000;
for ($i = 1; $i <= $N; $i++) {
    $ary[$i] = gen_random(1);
}
/*
for ($i=0; $i<$N; $i++) {
    printf("%4d %.15f\n", $i, $ary[$i]);
}
*/
heapsort($N, $ary);
printf("%.10f\n", $ary[$N]);
Exemplo n.º 4
0
function main_function()
{
    for ($i = 0; $i < 100; ++$i) {
        ackermann(4);
        ary(50000);
        ary2(50000);
        ary3(100);
        fibo(23);
        hash1(10000);
        hash2(200);
        heapsort(2000);
        matrix(3);
        nestedloop(8);
        sieve(5);
        strcat(80000);
        binary_trees(7);
        fannkuch(6);
    }
}
Exemplo n.º 5
0
    if ($r < $heap_size && $a[$largest] < $a[$r]) {
        $largest = $r;
    }
    if ($largest != $i) {
        $t = $a[$i];
        $a[$i] = $a[$largest];
        $a[$largest] = $t;
        heapify($a, $largest, $heap_size);
    }
}
function build_heap(&$a, &$heap_size)
{
    $len = floor($heap_size / 2);
    for ($i = $len; $i > -1; $i--) {
        heapify($a, $i, $heap_size);
    }
}
function heapsort(&$a)
{
    $heap_size = count($a);
    build_heap($a, $heap_size);
    while ($heap_size--) {
        $t = $a[$heap_size];
        $a[$heap_size] = $a[0];
        $a[0] = $t;
        build_heap($a, $heap_size);
    }
}
// 1 2 3 4 5 6 8
heapsort($a);
print_r($a);
Exemplo n.º 6
0
    return $t['sec'] + $t['usec'] / 1000000;
}
function start_test()
{
    ob_start();
    return getmicrotime();
}
function end_test($start, $name)
{
    global $total;
    $end = getmicrotime();
    ob_end_clean();
    $total += $end - $start;
    $num = number_format($end - $start, 3);
    $pad = str_repeat(" ", 24 - strlen($name) - strlen($num));
    echo $name . $pad . $num . "\n";
    ob_start();
    return getmicrotime();
}
function total()
{
    global $total;
    $pad = str_repeat("-", 24);
    echo $pad . "\n";
    $num = number_format($total, 3);
    $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num));
    echo "Total" . $pad . $num . "\n";
}
$t0 = $t = start_test();
heapsort(76000);
$t = end_test($t, "heapsort(20000)");
Exemplo n.º 7
0
function main_function()
{
    ackermann(2);
    ary(500);
    ary2(500);
    ary3(5);
    fibo(13);
    hash1(100);
    hash2(20);
    heapsort(200);
    matrix(3);
    nestedloop(3);
    sieve(1);
    strcat(80);
    binary_trees(3);
    fannkuch(6);
}
Exemplo n.º 8
0
 static function heapsort()
 {
     $N = 10000;
     for ($i = 1; $i <= $N; $i++) {
         $ary[$i] = Random::gen_random(1);
     }
     Timing::Start("heapsort.php");
     heapsort($N, $ary);
     Timing::Stop();
 }