3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo "<pre>"; $array = array(); $meanax = 300; for($i = 0; $i < $meanax; $i++) { $array[$i] = rand(0, $meanax-1); echo $array[$i]."\n"; } $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)); // 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.4.10.0110.00715.02
7.4.00.0110.00714.87
7.3.130.0070.01115.30
7.3.120.0140.00314.94
7.3.110.0070.01115.16
7.3.100.0060.00615.18
7.3.90.0090.00614.82
7.3.80.0110.00415.20
7.3.70.0090.00614.87
7.3.60.0030.01314.94
7.3.50.0040.00814.86
7.3.40.0090.00614.80
7.3.30.0040.01115.06
7.3.20.0030.01016.78
7.3.10.0030.01216.84
7.3.00.0070.00716.76
7.2.260.0110.00715.09
7.2.250.0040.01115.06
7.2.240.0090.00615.21
7.2.230.0060.01315.53
7.2.220.0070.00715.01
7.2.210.0060.00615.39
7.2.200.0000.01415.21
7.2.190.0080.00315.07
7.2.180.0090.00615.20
7.2.170.0100.01015.07
7.2.160.0100.00715.27
7.2.150.0140.00317.21
7.2.140.0070.00716.89
7.2.130.0060.01217.13
7.2.120.0030.00717.18
7.2.110.0060.00917.14
7.2.100.0040.00816.96
7.2.90.0080.00817.16
7.2.80.0030.01217.33
7.2.70.0060.00616.92
7.2.60.0040.01116.89
7.2.50.0090.00317.27
7.2.40.0090.00617.06
7.2.30.0110.00717.11
7.2.20.0030.01017.11
7.2.10.0000.01816.95
7.2.00.0060.00818.45
7.1.330.0100.00716.09
7.1.320.0100.00015.99
7.1.310.0000.01115.80
7.1.300.0090.00616.01
7.1.290.0060.01016.13
7.1.280.0070.01115.66
7.1.270.0100.00716.08
7.1.260.0030.01316.11
7.1.250.0000.01316.00
7.1.240.0030.01015.59
7.1.230.0130.00015.62
7.1.220.0030.00915.92
7.1.210.0030.00916.00
7.1.200.0060.00316.05
7.1.190.0070.01015.87
7.1.180.0000.01616.04
7.1.170.0080.00416.02
7.1.160.0100.00316.03
7.1.150.0060.01015.66
7.1.140.0060.01115.88
7.1.130.0000.01415.90
7.1.120.0030.01515.98
7.1.110.0110.00715.85
7.1.100.0080.00616.07
7.1.90.0070.00716.10
7.1.80.0060.00916.09
7.1.70.0080.00316.50
7.1.60.0050.01317.78
7.1.50.0080.01016.51
7.1.40.0030.01315.79
7.1.30.0060.01016.05
7.1.20.0030.01215.89
7.1.10.0030.01315.99
7.1.00.0050.04319.19
7.0.330.0100.00315.34
7.0.320.0060.00615.52
7.0.310.0060.00615.60
7.0.300.0090.00315.65
7.0.290.0040.01115.63
7.0.280.0090.00615.30
7.0.270.0070.00715.22
7.0.260.0040.00415.65
7.0.250.0000.01015.58
7.0.240.0000.01115.59
7.0.230.0000.01715.34
7.0.220.0090.00615.48
7.0.210.0070.01115.56
7.0.200.0100.00816.34
7.0.190.0030.01215.61
7.0.180.0070.01015.73
7.0.170.0090.00915.77
7.0.160.0030.01115.23
7.0.150.0030.01315.56
7.0.140.0080.03818.95
7.0.130.0070.00715.68
7.0.120.0060.01015.61
7.0.110.0130.00315.47
7.0.100.0050.04217.88
7.0.90.0160.03617.76
7.0.80.0120.04017.94
7.0.70.0060.03117.86
7.0.60.0130.04317.90
7.0.50.0180.03618.05
7.0.40.0080.03916.91
7.0.30.0050.02717.04
7.0.20.0050.03316.97
7.0.10.0080.02316.93
7.0.00.0090.02016.83
5.6.400.0030.01314.53
5.6.390.0030.01014.84
5.6.380.0060.01014.89
5.6.370.0070.00714.91
5.6.360.0060.00914.52
5.6.350.0090.00615.02
5.6.340.0080.00814.71
5.6.330.0030.01314.90
5.6.320.0070.01014.88
5.6.310.0060.00614.29
5.6.300.0070.01314.80
5.6.290.0110.00414.65
5.6.280.0080.03617.84
5.6.270.0000.01914.63
5.6.260.0040.01214.57
5.6.250.0050.04517.64
5.6.240.0050.03517.83
5.6.230.0080.03517.83
5.6.220.0050.03417.75
5.6.210.0150.04017.73
5.6.200.0120.04018.10
5.6.190.0060.04817.95
5.6.180.0070.02317.93
5.6.170.0050.02517.99
5.6.160.0000.03018.01
5.6.150.0080.02518.03
5.6.140.0050.02617.93
5.6.130.0060.02918.09
5.6.120.0050.02717.85
5.6.110.0050.02818.07
5.6.100.0030.03717.96
5.6.90.0050.02618.03
5.6.80.0050.02617.58
5.6.70.0050.02617.66
5.6.60.0020.02917.62
5.6.50.0030.02817.67
5.6.40.0030.02817.54
5.6.30.0120.02117.53
5.6.20.0020.02817.49
5.6.10.0100.03817.68
5.6.00.0070.02717.60
5.5.380.0120.03817.74
5.5.370.0080.04417.64
5.5.360.0100.04417.71
5.5.350.0050.04217.65
5.5.340.0050.02817.87
5.5.330.0080.03317.78
5.5.320.0050.02717.87
5.5.310.0040.02717.65
5.5.300.0060.02517.84
5.5.290.0110.02317.79
5.5.280.0030.02717.77
5.5.270.0080.03817.81
5.5.260.0020.02917.82
5.5.250.0030.03317.56
5.5.240.0080.01917.52
5.5.230.0060.03017.31
5.5.220.0080.02017.48
5.5.210.0080.02717.45
5.5.200.0100.02017.40
5.5.190.0030.02917.59
5.5.180.0030.03517.50
5.5.170.0000.01214.66
5.5.160.0050.02517.46
5.5.150.0090.02017.42
5.5.140.0100.04117.40
5.5.130.0070.04517.52
5.5.120.0100.04217.65
5.5.110.0120.03217.46
5.5.100.0080.04017.44
5.5.90.0020.03317.37
5.5.80.0120.03517.35
5.5.70.0060.04017.21
5.5.60.0050.04317.48
5.5.50.0100.02417.38
5.5.40.0020.04217.24
5.5.30.0080.02417.38
5.5.20.0100.05117.43
5.5.10.0100.04017.24
5.5.00.0050.04217.49
5.4.450.0050.03615.38
5.4.440.0070.03615.63
5.4.430.0030.02315.43
5.4.420.0050.04415.23
5.4.410.0040.02115.23
5.4.400.0060.02115.22
5.4.390.0020.02515.25
5.4.380.0050.02215.28
5.4.370.0050.02115.11
5.4.360.0030.02015.31
5.4.350.0070.02015.23
5.4.340.0100.01715.08
5.4.330.0060.00611.56
5.4.320.0050.02315.14
5.4.310.0080.03815.26
5.4.300.0070.04115.34
5.4.290.0060.03115.21
5.4.280.0070.04015.22
5.4.270.0050.03515.34
5.4.260.0050.03415.20
5.4.250.0050.02715.39
5.4.240.0050.04415.06
5.4.230.0070.04015.19
5.4.220.0090.03915.19
5.4.210.0060.03715.18
5.4.200.0050.04215.26
5.4.190.0080.03815.16
5.4.180.0030.03915.28
5.4.170.0060.02415.15
5.4.160.0030.04015.16
5.4.150.0100.03815.20
5.4.140.0070.01913.93
5.4.130.0050.02113.95
5.4.120.0030.03514.02
5.4.110.0040.04213.87
5.4.100.0080.03513.94
5.4.90.0050.04414.06
5.4.80.0050.03814.07
5.4.70.0100.03514.00
5.4.60.0080.01813.80
5.4.50.0020.02713.94
5.4.40.0050.04213.97
5.4.30.0080.04014.06
5.4.20.0080.03813.87
5.4.10.0030.04114.05
5.4.00.0020.04213.58
5.3.290.0070.02313.02
5.3.280.0090.04012.92
5.3.270.0050.04412.91
5.3.260.0050.04512.98
5.3.250.0020.04312.85
5.3.240.0080.04212.79
5.3.230.0060.03212.92
5.3.220.0070.04012.86
5.3.210.0120.03512.83
5.3.200.0080.04012.82
5.3.190.0060.04312.85
5.3.180.0120.03512.86
5.3.170.0120.03212.91
5.3.160.0050.04412.94
5.3.150.0100.04012.83
5.3.140.0050.04012.87
5.3.130.0030.02612.81
5.3.120.0080.03512.79
5.3.110.0090.05112.87
5.3.100.0070.04312.63
5.3.90.0170.01712.64
5.3.80.0050.02412.60
5.3.70.0070.04012.61
5.3.60.0020.03012.51
5.3.50.0020.03012.55
5.3.40.0050.02812.60
5.3.30.0070.03512.46
5.3.20.0020.03712.44
5.3.10.0110.03212.44
5.3.00.0030.04012.31
5.2.170.0070.03311.52
5.2.160.0000.03711.31
5.2.150.0030.05311.29
5.2.140.0030.06711.48
5.2.130.0030.03711.37
5.2.120.0070.04011.28
5.2.110.0070.05711.28
5.2.100.0100.04011.47
5.2.90.0100.05711.44
5.2.80.0100.06011.43
5.2.70.0130.05011.29
5.2.60.0030.06711.25
5.2.50.0030.05311.25
5.2.40.0030.06711.13
5.2.30.0070.05711.19
5.2.20.0000.04011.34
5.2.10.0030.06011.22
5.2.00.0030.05011.11
5.1.60.0130.03711.11
5.1.50.0070.03311.11
5.1.40.0170.01711.11
5.1.30.0000.04011.11
5.1.20.0000.06011.11
5.1.10.0070.05011.11
5.1.00.0100.05011.11
5.0.50.0070.03011.11
5.0.40.0030.04011.11
5.0.30.0100.06011.11
5.0.20.0100.01711.11
5.0.10.0000.02711.11
5.0.00.0000.04011.11
4.4.90.0000.02011.11
4.4.80.0030.03011.11
4.4.70.0030.02711.11
4.4.60.0030.03311.11
4.4.50.0030.03311.11
4.4.40.0030.04711.11
4.4.30.0030.02011.11
4.4.20.0000.02011.11
4.4.10.0000.03011.11
4.4.00.0000.03011.11
4.3.110.0070.02311.11
4.3.100.0000.02011.11
4.3.90.0000.02011.11
4.3.80.0030.02711.11
4.3.70.0000.02711.11
4.3.60.0030.03311.11
4.3.50.0030.03011.11
4.3.40.0000.03011.11
4.3.30.0000.03711.11
4.3.20.0070.01311.11
4.3.10.0030.04011.11
4.3.00.0000.03711.11

preferences:
41.56 ms | 401 KiB | 5 Q