3v4l.org

run code in 300+ PHP versions simultaneously
<?php <?php function linear_regression($x, $y) { // calculate number points $n = count($x); // ensure both arrays of points are the same size if ($n != count($y)) { trigger_error("linear_regression(): Number of elements in coordinate arrays do not match.", E_USER_ERROR); } // calculate sums $x_sum = array_sum($x); $y_sum = array_sum($y); $xx_sum = 0; $xy_sum = 0; for($i = 0; $i < $n; $i++) { $xy_sum+=($x[$i]*$y[$i]); $xx_sum+=($x[$i]*$x[$i]); } // calculate slope //$m = (($n * $xy_sum) - ($x_sum * $y_sum)) / (($n * $xx_sum) - ($x_sum * $x_sum)); $divisor = $n * $xx_sum - $x_sum * $x_sum; if ($divisor == 0){ $m = 0; } else { $m = (($n * $xy_sum) – ($x_sum * $y_sum)) / $divisor; } // calculate intercept $b = ($y_sum - ($m * $x_sum)) / $n; // return result return array("m"=>$m, "b"=>$b); } var_dump( linear_regression(array(1, 2, 3, 4, 4), array(1.5, 1.6, 2.1, 3.0, 6)) );

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.210.0120.04212.37
5.4.200.0110.04312.37
5.4.190.0140.05112.37
5.4.180.0100.03912.37
5.4.170.0150.03612.38
5.4.160.0120.03912.37
5.4.150.0180.04912.37
5.4.140.0100.04212.06
5.4.130.0110.04212.04
5.4.120.0130.03812.01
5.4.110.0120.04012.01
5.4.100.0090.04412.00
5.4.90.0120.04612.01
5.4.80.0160.06712.01
5.4.70.0100.03912.00
5.4.60.0100.04112.00
5.4.50.0130.03812.00
5.4.40.0130.03611.99
5.4.30.0120.04211.98
5.4.20.0120.03811.98
5.4.10.0120.03611.98
5.4.00.0120.03711.48
5.3.270.0140.03912.72
5.3.260.0080.04512.72
5.3.250.0120.04312.72
5.3.240.0120.04312.72
5.3.230.0120.04112.71
5.3.220.0110.04112.68
5.3.210.0100.04512.68
5.3.200.0140.03912.68
5.3.190.0100.04712.67
5.3.180.0140.04112.67
5.3.170.0110.04712.67
5.3.160.0130.04212.68
5.3.150.0110.04212.67
5.3.140.0130.04012.66
5.3.130.0120.04112.66
5.3.120.0130.04212.66
5.3.110.0100.04312.66
5.3.100.0090.04412.12
5.3.90.0120.03912.08
5.3.80.0130.04112.08
5.3.70.0240.05812.07
5.3.60.0110.04012.06
5.3.50.0120.03812.00
5.3.40.0110.04012.00
5.3.30.0120.03811.94
5.3.20.0100.04011.72
5.3.10.0120.03511.69
5.3.00.0100.03911.67

preferences:
142.77 ms | 1386 KiB | 7 Q