3v4l.org

run code in 300+ PHP versions simultaneously
<?php function distribute ($sum, $number, $base = 130, $part2 = 30 ,$relation = 4, &$h3=12, $debug=false) { $outp = ""; $result = array(); $outp.= "SUM: $sum <br> NUM: $number <br> BASE: $base <br>"; $C2 = $relation; $p1 = min (3,$number); $p2 = floor(($number-$p1) * $part2); $outp .= "$number $p1 $part2 <br>" ; $b = $number * $base; $p3 = $number - ($p1 + $p2); $outp.= "part1: $p1<br> part2: $p2<br> part3: $p3 <br><br>"; if ($debug) echo $h3; if ($h3==-1) $h3=ceil(($number/5)*ceil($base/10)); if ($debug) echo $h3; $v3 = $h3 * ($p1+$p2); $t3=0; $hh = triangleHeights($h3,$p3); $k=0; for ($i=$p1+$p2+1; $i<=$p1+$p2+$p3; $i++) { $result[$i]=$base+$hh[$k]; $t3+=$hh[$k]; $k++; } $top = $sum - $b - $t3 - $v3; / $h2=floor($top / ($p1+0.5*$C2*$p1+0.5*$p2)); $h1=$C2*$h2; if ($h2 == 0 ) $h1=2*$top/$p1; $v2 = $h2 * $p1; $t1 = floor(($p1 * $h1) / 2.0); $t2 = floor(($p2 * $h2) / 2.0); $left = $top - ($t1+$t2+$v2); if ($left>0 && $t1>0) { $hTmp = (($t1+$left)*$h1)/$t1; $h1=$hTmp; $t1 += $left; } $outp.= "t1: $t1<br>t2: $t2<br>t3: $t3<br><br>"; if ($p2>0) { $hh = triangleHeights($h2,$p2,$t2); $sm = 0; $k=0; for ($i=$p1+1;$i<=$p1+$p2;$i++) { $result[$i]=$base+$h3+$hh[$k]; $sm += $hh[$k]; $k++; } $outp .="Sum2 is $sm! <br>"; } if ($p1>0) { $hh = triangleHeights($h1,$p1,$t1); $sm = 0; $k=0; for ($i=1;$i<=$p1;$i++) { $result[$i]=$base+$h2+$h3+$hh[$k]; $sm += $hh[$k]; $k++; } $outp .="Sum1 is $sm! <br>"; } $outp.= "h1: $h1<br>h2: $h2<br>h3: $h3<br><br>"; $outp.= "v2: $v2<br>v3: $v3 <br> b: $b <br> top: $top<br><br>"; $sum = 0; for ($i=1;$i<=$number;$i++) { $sum += $result[$i]; } $outp.= "SUM is $sum<br>"; if ($debug) echo $outp; if ($top<0) $result[1]=-1; return $result; } function triangleHeights ($h, $w, $sum=0) { $heights = array(); for ($i=0;$i<$w;$i++) { $hi = ($h*($w-$i)/$w); $hi1 = ($h*($w-($i+1))/$w); $heights [$i]=floor(($hi+$hi1)/2.0);; $sum-=$heights[$i]; } while ($sum>0) { $i=0; while ($sum>0 && $i<$w) { $heights[$i]++; $sum--; $i++; } } return $heights; } print_r(distribute(90,10,100));

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).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.340.0060.04912.03
5.4.320.0050.04812.53
5.4.310.0110.04312.53
5.4.300.0090.05212.53
5.4.290.0110.04712.52
5.4.280.0080.04912.42
5.4.270.0090.05112.42
5.4.260.0120.04312.42
5.4.250.0060.04412.42
5.4.240.0080.04212.42
5.4.230.0050.04412.41
5.4.220.0060.03812.41
5.4.210.0080.03812.41
5.4.200.0080.03812.41
5.4.190.0080.03512.41
5.4.180.0050.03712.41
5.4.170.0050.04812.42
5.4.160.0070.03812.41
5.4.150.0080.03812.41
5.4.140.0090.04012.10
5.4.130.0070.04412.08
5.4.120.0090.04412.04
5.4.110.0040.04112.04
5.4.100.0120.04812.04
5.4.90.0060.04412.05
5.4.80.0080.04412.05
5.4.70.0090.03712.04
5.4.60.0070.03912.04
5.4.50.0090.06012.04
5.4.40.0140.06212.03
5.4.30.0100.03712.02
5.4.20.0090.03812.02
5.4.10.0060.03612.02
5.4.00.0090.03811.52
5.3.290.0090.04512.80
5.3.280.0040.04512.70
5.3.270.0080.05712.73
5.3.260.0080.05212.72
5.3.250.0090.04112.72
5.3.240.0070.04412.71
5.3.230.0100.04012.70
5.3.220.0090.04512.68
5.3.210.0170.06612.68
5.3.200.0130.09812.68
5.3.190.0130.07212.68
5.3.180.0170.07912.67
5.3.170.0190.07612.67
5.3.160.0170.08512.68
5.3.150.0110.06712.67
5.3.140.0070.07912.66
5.3.130.0190.07612.66
5.3.120.0170.05412.66
5.3.110.0090.05312.65
5.3.100.0070.05112.14
5.3.90.0090.04112.12
5.3.80.0090.03812.11
5.3.70.0040.04312.11
5.3.60.0060.04212.10
5.3.50.0130.05512.04
5.3.40.0110.04512.04
5.3.30.0060.04112.00
5.3.20.0060.04311.78
5.3.10.0070.03811.75
5.3.00.0070.03911.73
5.2.170.0170.0469.23
5.2.160.0070.0389.24
5.2.150.0100.0409.24
5.2.140.0200.0559.23
5.2.130.0050.0389.20
5.2.120.0050.0389.20
5.2.110.0050.0399.21
5.2.100.0070.0409.20
5.2.90.0100.0309.20
5.2.80.0040.0319.20
5.2.70.0110.0489.20
5.2.60.0170.0749.15
5.2.50.0100.0419.12
5.2.40.0040.0409.09
5.2.30.0110.0379.07
5.2.20.0060.0429.06
5.2.10.0080.0378.97
5.2.00.0150.0628.82
5.1.60.0030.0368.12
5.1.50.0050.0328.11
5.1.40.0050.0278.09
5.1.30.0030.0318.43
5.1.20.0020.0358.46
5.1.10.0080.0278.19
5.1.00.0060.0348.19
5.0.50.0110.0676.68
5.0.40.0090.0186.53
5.0.30.0040.0366.35
5.0.20.0060.0236.31
5.0.10.0050.0366.29
5.0.00.0100.0406.28
4.4.90.0040.0204.78
4.4.80.0060.0274.75
4.4.70.0040.0164.75
4.4.60.0040.0254.76
4.4.50.0060.0404.77
4.4.40.0060.0354.70
4.4.30.0050.0214.75
4.4.20.0050.0214.84
4.4.10.0020.0274.85
4.4.00.0060.0344.76
4.3.110.0030.0184.67
4.3.100.0020.0184.67
4.3.90.0030.0164.63
4.3.80.0020.0264.58
4.3.70.0020.0164.63
4.3.60.0060.0114.63
4.3.50.0030.0164.63
4.3.40.0060.0224.54
4.3.30.0030.0163.30
4.3.20.0030.0143.28
4.3.10.0030.0163.24
4.3.00.0070.0207.09

preferences:
141.23 ms | 1394 KiB | 7 Q