@ 2014-10-14T07:36:39Z <?php
if (function_exists("date_default_timezone_set")) {
date_default_timezone_set("UTC");
}
function simple() {
$a = 0;
for ($i = 0; $i < 1000000; $i++)
$a++;
$thisisanotherlongname = 0;
for ($thisisalongname = 0; $thisisalongname < 1000000; $thisisalongname++)
$thisisanotherlongname++;
}
/****/
function simplecall() {
for ($i = 0; $i < 1000000; $i++)
strlen("hallo");
}
/****/
function hallo($a) {
}
function simpleucall() {
for ($i = 0; $i < 1000000; $i++)
hallo("hallo");
}
/****/
function simpleudcall() {
for ($i = 0; $i < 1000000; $i++)
hallo2("hallo");
}
function hallo2($a) {
}
/****/
function mandel() {
$w1=50;
$h1=150;
$recen=-.45;
$imcen=0.0;
$r=0.7;
$s=0; $rec=0; $imc=0; $re=0; $im=0; $re2=0; $im2=0;
$x=0; $y=0; $w2=0; $h2=0; $color=0;
$s=2*$r/$w1;
$w2=40;
$h2=12;
for ($y=0 ; $y<=$w1; $y=$y+1) {
$imc=$s*($y-$h2)+$imcen;
for ($x=0 ; $x<=$h1; $x=$x+1) {
$rec=$s*($x-$w2)+$recen;
$re=$rec;
$im=$imc;
$color=1000;
$re2=$re*$re;
$im2=$im*$im;
while( ((($re2+$im2)<1000000) && $color>0)) {
$im=$re*$im*2+$imc;
$re=$re2-$im2+$rec;
$re2=$re*$re;
$im2=$im*$im;
$color=$color-1;
}
if ( $color==0 ) {
print "_";
} else {
print "#";
}
}
print "<br>";
flush();
}
}
/****/
function mandel2() {
$b = " .:,;!/>)|&IH%*#";
//float r, i, z, Z, t, c, C;
for ($y=30; printf("\n"), $C = $y*0.1 - 1.5, $y--;){
for ($x=0; $c = $x*0.04 - 2, $z=0, $Z=0, $x++ < 75;){
for ($r=$c, $i=$C, $k=0; $t = $z*$z - $Z*$Z + $r, $Z = 2*$z*$Z + $i, $z=$t, $k<5000; $k++)
if ($z*$z + $Z*$Z > 500000) break;
echo $b[$k%16];
}
}
}
/****/
function Ack($m, $n){
if($m == 0) return $n+1;
if($n == 0) return Ack($m-1, 1);
return Ack($m - 1, Ack($m, ($n - 1)));
}
function ackermann($n) {
$r = Ack(3,$n);
print "Ack(3,$n): $r\n";
}
/****/
function ary($n) {
for ($i=0; $i<$n; $i++) {
$X[$i] = $i;
}
for ($i=$n-1; $i>=0; $i--) {
$Y[$i] = $X[$i];
}
$last = $n-1;
print "$Y[$last]\n";
}
/****/
function ary2($n) {
for ($i=0; $i<$n;) {
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
$X[$i] = $i; ++$i;
}
for ($i=$n-1; $i>=0;) {
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
$Y[$i] = $X[$i]; --$i;
}
$last = $n-1;
print "$Y[$last]\n";
}
/****/
function ary3($n) {
for ($i=0; $i<$n; $i++) {
$X[$i] = $i + 1;
$Y[$i] = 0;
}
for ($k=0; $k<1000; $k++) {
for ($i=$n-1; $i>=0; $i--) {
$Y[$i] += $X[$i];
}
}
$last = $n-1;
print "$Y[0] $Y[$last]\n";
}
/****/
function fibo_r($n){
return(($n < 2) ? 1 : fibo_r($n - 2) + fibo_r($n - 1));
}
function fibo($n) {
$r = fibo_r($n);
print "$r\n";
}
/****/
function hash1($n) {
for ($i = 1; $i <= $n; $i++) {
$X[dechex($i)] = $i;
}
$c = 0;
for ($i = $n; $i > 0; $i--) {
if ($X[dechex($i)]) { $c++; }
}
print "$c\n";
}
/****/
function hash2($n) {
for ($i = 0; $i < $n; $i++) {
$hash1["foo_$i"] = $i;
$hash2["foo_$i"] = 0;
}
for ($i = $n; $i > 0; $i--) {
foreach($hash1 as $key => $value) $hash2[$key] += $value;
}
$first = "foo_0";
$last = "foo_".($n-1);
print "$hash1[$first] $hash1[$last] $hash2[$first] $hash2[$last]\n";
}
/****/
function gen_random ($n) {
global $LAST;
return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM );
}
function heapsort_r($n, &$ra) {
$l = ($n >> 1) + 1;
$ir = $n;
while (1) {
if ($l > 1) {
$rra = $ra[--$l];
} else {
$rra = $ra[$ir];
$ra[$ir] = $ra[1];
if (--$ir == 1) {
$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;
}
}
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]);
}
/****/
function mkmatrix ($rows, $cols) {
$count = 1;
$mx = array();
for ($i=0; $i<$rows; $i++) {
for ($j=0; $j<$cols; $j++) {
$mx[$i][$j] = $count++;
}
}
return($mx);
}
function mmult ($rows, $cols, $m1, $m2) {
$m3 = array();
for ($i=0; $i<$rows; $i++) {
for ($j=0; $j<$cols; $j++) {
$x = 0;
for ($k=0; $k<$cols; $k++) {
$x += $m1[$i][$k] * $m2[$k][$j];
}
$m3[$i][$j] = $x;
}
}
return($m3);
}
function matrix($n) {
$SIZE = 30;
$m1 = mkmatrix($SIZE, $SIZE);
$m2 = mkmatrix($SIZE, $SIZE);
while ($n--) {
$mm = mmult($SIZE, $SIZE, $m1, $m2);
}
print "{$mm[0][0]} {$mm[2][3]} {$mm[3][2]} {$mm[4][4]}\n";
}
/****/
function nestedloop($n) {
$x = 0;
for ($a=0; $a<$n; $a++)
for ($b=0; $b<$n; $b++)
for ($c=0; $c<$n; $c++)
for ($d=0; $d<$n; $d++)
for ($e=0; $e<$n; $e++)
for ($f=0; $f<$n; $f++)
$x++;
print "$x\n";
}
/****/
function sieve($n) {
$count = 0;
while ($n-- > 0) {
$count = 0;
$flags = range (0,8192);
for ($i=2; $i<8193; $i++) {
if ($flags[$i] > 0) {
for ($k=$i+$i; $k <= 8192; $k+=$i) {
$flags[$k] = 0;
}
$count++;
}
}
}
print "Count: $count\n";
}
/****/
function strcat($n) {
$str = "";
while ($n-- > 0) {
$str .= "hello\n";
}
$len = strlen($str);
print "$len\n";
}
/*****/
function getmicrotime()
{
$t = gettimeofday();
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();
simple();
$t = end_test($t, "simple");
simplecall();
$t = end_test($t, "simplecall");
simpleucall();
$t = end_test($t, "simpleucall");
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");
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.010 0.584 22.48 8.3.5 0.027 0.598 24.10 8.3.4 0.017 0.552 23.76 8.3.3 0.017 0.554 24.08 8.3.2 0.010 0.304 25.26 8.3.1 0.010 0.303 24.72 8.3.0 0.003 0.300 23.66 8.2.18 0.023 0.588 21.54 8.2.17 0.023 0.568 23.86 8.2.16 0.010 0.545 25.59 8.2.15 0.010 0.332 24.25 8.2.14 0.017 0.332 24.66 8.2.13 0.013 0.334 26.16 8.2.12 0.003 0.325 26.23 8.2.11 0.013 0.517 25.43 8.2.10 0.017 0.386 23.25 8.2.9 0.007 0.416 24.29 8.2.8 0.007 0.389 22.54 8.2.7 0.006 0.424 22.30 8.2.6 0.010 0.392 22.84 8.2.5 0.010 0.386 22.54 8.2.4 0.010 0.379 23.14 8.2.3 0.000 0.394 23.21 8.2.2 0.007 0.393 22.71 8.2.1 0.003 0.399 23.14 8.2.0 0.003 0.391 22.82 8.1.28 0.017 0.617 25.92 8.1.27 0.007 0.348 30.07 8.1.26 0.007 0.333 28.74 8.1.25 0.010 0.329 28.09 8.1.24 0.010 0.527 30.02 8.1.23 0.010 0.389 25.59 8.1.22 0.013 0.393 24.16 8.1.21 0.013 0.432 23.90 8.1.20 0.007 0.395 23.85 8.1.19 0.013 0.388 23.86 8.1.18 0.010 0.412 24.03 8.1.17 0.010 0.378 25.08 8.1.16 0.013 0.363 28.48 8.1.15 0.013 0.408 25.35 8.1.14 0.013 0.392 23.97 8.1.13 0.007 0.382 24.40 8.1.12 0.007 0.385 23.82 8.1.11 0.010 0.410 23.90 8.1.10 0.000 0.417 23.96 8.1.9 0.013 0.374 23.93 8.1.8 0.003 0.389 23.96 8.1.7 0.007 0.394 23.99 8.1.6 0.013 0.515 24.03 8.1.5 0.003 0.522 23.99 8.1.4 0.003 0.526 23.87 8.1.3 0.007 0.525 23.89 8.1.2 0.007 0.520 24.06 8.1.1 0.007 0.522 23.93 8.1.0 0.000 0.524 23.95 8.0.30 0.003 0.388 23.60 8.0.29 0.013 0.395 23.13 8.0.28 0.010 0.401 24.83 8.0.27 0.003 0.403 23.55 8.0.26 0.003 0.405 23.67 8.0.25 0.010 0.382 23.29 8.0.24 0.007 0.401 23.28 8.0.23 0.003 0.395 23.16 8.0.22 0.010 0.398 23.11 8.0.21 0.000 0.420 23.18 8.0.20 0.010 0.396 23.31 8.0.19 0.007 0.527 23.21 8.0.18 0.003 0.526 23.23 8.0.17 0.003 0.524 23.32 8.0.16 0.007 0.522 23.18 8.0.15 0.003 0.527 23.14 8.0.14 0.003 0.520 23.04 8.0.13 0.007 0.520 19.79 8.0.12 0.007 0.522 23.18 8.0.11 0.007 0.522 23.17 8.0.10 0.003 0.522 23.19 8.0.9 0.007 0.523 23.04 8.0.8 0.029 0.780 23.19 8.0.7 0.007 0.523 23.26 8.0.6 0.003 0.522 23.17 8.0.5 0.010 0.520 23.23 8.0.3 0.034 0.792 23.32 8.0.2 0.016 0.749 23.21 8.0.1 0.013 0.540 23.23 8.0.0 0.036 0.720 23.20 7.4.33 0.000 0.471 21.11 7.4.32 0.007 0.434 22.78 7.4.30 0.007 0.434 22.76 7.4.29 0.007 0.569 22.88 7.4.28 0.013 0.568 22.78 7.4.27 0.007 0.575 22.88 7.4.26 0.007 0.571 22.76 7.4.25 0.007 0.575 22.76 7.4.24 0.013 0.579 22.78 7.4.23 0.007 0.570 22.90 7.4.22 0.017 1.038 22.64 7.4.21 0.010 0.903 22.92 7.4.20 0.003 0.573 22.94 7.4.16 0.023 0.776 22.82 7.4.15 0.030 0.788 22.92 7.4.14 0.030 0.801 22.74 7.4.13 0.021 0.800 22.98 7.4.12 0.021 0.771 22.89 7.4.11 0.023 0.972 22.77 7.4.10 0.033 0.912 22.74 7.4.9 0.016 0.853 22.76 7.4.8 0.023 0.812 22.98 7.4.7 0.023 0.797 22.89 7.4.6 0.010 0.773 22.90 7.4.5 0.010 0.407 22.73 7.4.4 0.020 0.918 22.90 7.4.3 0.023 0.805 22.78 7.4.0 0.017 0.773 21.38 7.3.33 0.010 0.636 19.80 7.3.32 0.013 0.597 19.63 7.3.31 0.013 0.588 22.70 7.3.30 0.010 0.592 22.68 7.3.29 0.013 0.958 22.64 7.3.28 0.027 1.054 22.67 7.3.27 0.026 1.001 22.70 7.3.26 0.020 0.957 22.79 7.3.25 0.021 0.965 22.82 7.3.24 0.026 1.091 22.72 7.3.23 0.020 0.940 22.67 7.3.21 0.026 0.982 22.88 7.3.20 0.023 1.013 22.74 7.3.19 0.033 1.355 22.86 7.3.18 0.029 1.035 22.63 7.3.17 0.013 1.029 22.79 7.3.16 0.030 0.935 22.67 7.2.33 0.036 1.024 22.57 7.2.32 0.019 0.952 22.52 7.2.31 0.026 1.433 22.79 7.2.30 0.013 1.016 22.69 7.2.29 0.033 0.938 22.29 7.2.6 0.007 0.514 22.65 7.2.0 0.000 0.591 25.61 7.1.20 0.013 0.553 21.89 7.1.10 0.003 0.700 24.36 7.1.7 0.003 0.543 23.14 7.1.6 0.010 0.683 23.09 7.1.5 0.007 0.561 22.85 7.0.20 0.010 0.708 22.92
preferences:dark mode live preview
36.18 ms | 401 KiB | 5 Q