3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(); $meanax = 300; for($i = 0; $i < $meanax; $i++) { $array[$i] = rand(0, $meanax-1); } $s = sd($array); $mean = array_sum($array) / count($array); echo "\nbefore\n"; var_dump(array('s' => $s, 'm' => $mean)); $n = count($array); $x_new = 100000000; $x_quer_strich = m_reverse($n, $mean, $x_new); $s_new = sd_reverse($s, $n, $x_new, $x_quer_strich); echo "\nreverse\n"; var_dump(array('s' => $s_new, 'm' => $x_quer_strich)); $array[$n+1] = $x_new; $s = sd($array); $mean = array_sum($array) / count($array); echo "\nafter\n"; var_dump(array('s' => $s, 'm' => $mean)); echo "\nvalues array\n"; var_dump($array); // Function to calculate square of value - mean function sd_square($x, $mean) { return pow($x - $mean,2); } // Function to calculate standard deviation (uses sd_square) function sd($array) { // square root of sum of squares devided by N-1 return sqrt(array_sum(array_map("sd_square", $array, array_fill(0,count($array), (array_sum($array) / count($array)) ) ) ) / (count($array)-1) ); } function m_reverse($n, $mean, $x) { return ( $n * $mean + $x ) / ( $n + 1 ); } function sd_reverse($s, $n, $x, $mean) { return sqrt( 1 / $n * ( ( $n - 1 ) * pow( $s, 2 ) + ( $x - $mean ) ) ); }

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)
7.1.70.0150.00317.02
7.1.60.0050.01217.45
7.1.50.0090.00717.05
7.1.40.0000.01417.04
7.1.30.0170.00016.59
7.1.20.0090.01316.78
7.1.10.0070.00716.70
7.1.00.0100.00516.87
7.0.200.0050.00716.95
7.0.190.0110.00016.75
7.0.180.0040.00816.48
7.0.170.0080.00416.48
7.0.160.0070.00516.48
7.0.150.0000.01416.48
7.0.140.0060.01316.49
7.0.130.0130.00317.04
7.0.120.0080.00816.71
7.0.110.0070.00716.57
7.0.100.0040.01216.52
7.0.90.0100.00316.48
7.0.80.0040.00816.62
7.0.70.0150.00216.48
7.0.60.0080.00816.48
7.0.50.0030.01016.56
7.0.40.0100.00516.48
7.0.30.0000.01216.48
7.0.20.0060.00616.48
7.0.10.0100.00316.48
7.0.00.0080.00416.48
5.6.300.0030.04521.11
5.6.290.0100.04020.99
5.6.280.0100.04221.04
5.6.270.0100.07621.29
5.6.260.0000.05521.02
5.6.250.0130.06021.02
5.6.240.0070.04321.05
5.6.230.0040.05221.20
5.6.220.0040.05921.12
5.6.210.0090.03821.05
5.6.200.0070.04921.15
5.6.190.0060.04320.99
5.6.180.0030.04521.09
5.6.170.0070.04221.09
5.6.160.0060.04820.97
5.6.150.0000.04721.02
5.6.140.0090.04421.20
5.6.130.0060.04320.91
5.6.120.0030.04920.91
5.6.110.0030.05221.14
5.6.100.0130.08020.98
5.6.90.0100.05221.11
5.6.80.0030.04220.43
5.6.70.0130.04920.39
5.6.60.0040.05720.36
5.6.50.0080.04220.36
5.6.40.0100.06320.35
5.6.30.0070.06320.34
5.6.20.0070.03820.56
5.6.10.0040.04620.54
5.6.00.0060.04220.32
5.5.380.0030.04417.77
5.5.370.0070.03817.66
5.5.360.0030.04017.66
5.5.350.0070.04117.74
5.5.340.0030.04318.23
5.5.330.0060.04518.25
5.5.320.0070.03918.16
5.5.310.0060.03818.16
5.5.300.0060.03818.22
5.5.290.0070.03917.97
5.5.280.0070.03918.16
5.5.270.0070.07018.20
5.5.260.0070.04417.83
5.5.250.0040.06018.06
5.5.240.0040.04417.36
5.5.230.0040.04017.35
5.5.220.0100.03217.62
5.5.210.0030.04417.36
5.5.200.0070.07117.20
5.5.190.0060.03817.60
5.5.180.0140.04417.51
5.5.160.0000.07117.54
5.5.150.0040.04017.57
5.5.140.0030.04117.59
5.5.130.0070.07317.17
5.5.120.0070.05917.55
5.5.110.0110.03217.32
5.5.100.0200.05317.46
5.5.90.0030.04517.45
5.5.80.0070.03817.38
5.5.70.0130.04317.50
5.5.60.0100.04017.45
5.5.50.0040.04417.37
5.5.40.0150.02817.34
5.5.30.0030.04117.31
5.5.20.0090.04717.40
5.5.10.0130.03017.44
5.5.00.0070.04217.40
5.4.450.0100.04219.68
5.4.440.0030.04419.37
5.4.430.0000.04419.48
5.4.420.0000.04519.36
5.4.410.0030.05219.38
5.4.400.0090.03819.29
5.4.390.0030.05619.08
5.4.380.0130.04019.00
5.4.370.0000.04219.21
5.4.360.0030.07118.98
5.4.350.0000.04618.98
5.4.340.0030.04719.10
5.4.320.0070.04319.20
5.4.310.0070.03619.04
5.4.300.0000.04219.23
5.4.290.0000.04219.07
5.4.280.0030.04819.11
5.4.270.0070.04319.36
5.4.260.0040.03919.38
5.4.250.0040.03919.13
5.4.240.0070.04519.06
5.4.230.0030.04319.14
5.4.220.0000.04419.34
5.4.210.0100.03619.17
5.4.200.0030.04119.03
5.4.190.0070.03919.03
5.4.180.0040.03919.19
5.4.170.0070.03818.98
5.4.160.0000.05018.96
5.4.150.0070.05319.34
5.4.140.0070.04016.84
5.4.130.0070.03316.88
5.4.120.0140.03516.63
5.4.110.0030.04316.78
5.4.100.0000.04316.82
5.4.90.0100.03516.87
5.4.80.0100.03216.85
5.4.70.0100.03316.89
5.4.60.0030.04116.61
5.4.50.0030.04316.79
5.4.40.0030.03716.79
5.4.30.0150.06116.72
5.4.20.0070.03116.52
5.4.10.0070.07316.52
5.4.00.0030.03816.48
5.3.290.0030.04316.48
5.3.280.0030.04316.48
5.3.270.0090.03516.48
5.3.260.0070.03716.48
5.3.250.0030.04516.48
5.3.240.0030.04116.48
5.3.230.0000.04416.48
5.3.220.0070.04116.48
5.3.210.0100.03316.48
5.3.200.0100.03316.48
5.3.190.0040.04316.48
5.3.180.0030.04216.48
5.3.170.0030.04216.48
5.3.160.0030.04316.48
5.3.150.0090.03116.48
5.3.140.0000.04016.48
5.3.130.0090.04016.48
5.3.120.0070.06416.48
5.3.110.0000.04616.48
5.3.100.0000.04216.48
5.3.90.0030.06616.48
5.3.80.0100.06516.48
5.3.70.0100.06516.48
5.3.60.0030.04816.48
5.3.50.0060.03916.48
5.3.40.0000.04016.48
5.3.30.0090.03516.48
5.3.20.0030.03416.48
5.3.10.0030.04716.48
5.3.00.0030.03616.48
5.2.170.0000.03716.48
5.2.160.0060.03116.48
5.2.150.0030.03016.48
5.2.140.0070.02616.48
5.2.130.0080.02416.48
5.2.120.0070.05516.48
5.2.110.0030.02916.48
5.2.100.0060.02816.48
5.2.90.0060.03516.48
5.2.80.0030.03016.48
5.2.70.0030.03216.48
5.2.60.0000.03616.48
5.2.50.0070.04616.48
5.2.40.0000.04516.48
5.2.30.0060.05716.48
5.2.20.0030.04016.48
5.2.10.0000.04516.48
5.2.00.0000.05416.48
5.1.60.0030.03116.48
5.1.50.0030.02616.48
5.1.40.0070.03916.48
5.1.30.0070.05416.48
5.1.20.0000.05516.48
5.1.10.0000.05516.48
5.1.00.0030.05216.48
5.0.50.0030.02216.48
5.0.40.0000.02416.48
5.0.30.0030.03116.48
5.0.20.0000.02216.48
5.0.10.0000.02416.48
5.0.00.0180.01816.48
4.4.90.0040.01416.48
4.4.80.0000.01816.48
4.4.70.0040.03516.48
4.4.60.0000.01916.48
4.4.50.0000.03616.48
4.4.40.0060.05016.48
4.4.30.0030.03716.48
4.4.20.0030.02116.48
4.4.10.0040.01916.48
4.4.00.0000.03016.48
4.3.110.0000.01916.48
4.3.100.0000.01816.48
4.3.90.0070.01016.48
4.3.80.0070.02616.48
4.3.70.0030.01416.48
4.3.60.0030.01516.48
4.3.50.0030.01516.48
4.3.40.0030.04016.48
4.3.30.0000.02116.48
4.3.20.0000.02016.48
4.3.10.0030.01716.48
4.3.00.0000.02016.48

preferences:
39.81 ms | 401 KiB | 5 Q