3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * An array in DESCENDING order (OP) */ $array = [ 61029, 64698, 67355, 70000, // has bubble 43651, 48346, 52029, // has bubble 48029, 48698, 49355, 50000, ]; /** * An array in ASCENDING order */ $asc_array = [ 10, 20, 30, 40, 50, 45, //Has bubble 55 ]; /** * Given an array, identify a "bubble", aka. an increasing value in an otherwise decreasing value array. * Returns the $key where the bubble resides. */ function identifyBubble($array){ foreach($array as $id => $item){ if(!$id){ continue; } if(!$array[$id+1]){ continue; } if(($array[$id-1] < $array[$id]) && ($array[$id] > $array[$id+1])){ return $id; } } return false; } /** * If an array is in ASCENDING order, switch it around, * otherwise return the array as is. */ function makeArrayDescending($array){ if(reset($array) < end($array)){ return array_values(array_reverse($array)); } return $array; } var_dump(identifyBubble($array)); var_dump(makeArrayDescending($asc_array)); var_dump(identifyBubble(makeArrayDescending($asc_array)));

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)
8.3.80.0030.00918.30
8.3.70.0140.01016.63
8.3.60.0070.00718.31
8.3.50.0100.00918.07
8.3.40.0160.00318.76
8.3.30.0070.00718.61
8.3.20.0060.00320.78
8.3.10.0040.00420.66
8.3.00.0040.00422.39
8.2.200.0050.00516.47
8.2.190.0080.00816.58
8.2.180.0110.00718.54
8.2.170.0000.01418.94
8.2.160.0080.00622.96
8.2.150.0040.00425.66
8.2.140.0040.00424.66
8.2.130.0040.00418.16
8.2.120.0050.00326.35
8.2.110.0030.00619.33
8.2.100.0110.00017.91
8.2.90.0000.00720.42
8.2.80.0000.00820.50
8.2.70.0000.00817.63
8.2.60.0050.00717.93
8.2.50.0050.00318.07
8.2.40.0070.00219.88
8.2.30.0030.00518.03
8.2.20.0000.00718.14
8.2.10.0000.00819.47
8.2.00.0020.00517.99
8.1.290.0030.00630.84
8.1.280.0000.01425.92
8.1.270.0090.00020.30
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00323.91
8.1.230.0110.00020.98
8.1.220.0000.00817.78
8.1.210.0040.00418.88
8.1.200.0030.00617.36
8.1.190.0000.00917.23
8.1.180.0040.00418.66
8.1.170.0050.00320.11
8.1.160.0050.00218.94
8.1.150.0030.00618.81
8.1.140.0040.00420.20
8.1.130.0030.00620.24
8.1.120.0000.00717.38
8.1.110.0000.00817.38
8.1.100.0040.00417.36
8.1.90.0070.00017.50
8.1.80.0040.00417.50
8.1.70.0040.00417.45
8.1.60.0070.00017.49
8.1.50.0040.00417.55
8.1.40.0030.00617.54
8.1.30.0050.00517.50
8.1.20.0000.00817.58
8.1.10.0040.00417.61
8.1.00.0060.00317.51
8.0.300.0060.00320.03
8.0.290.0040.00416.63
8.0.280.0000.00718.47
8.0.270.0080.00016.72
8.0.260.0050.00218.38
8.0.250.0060.00316.88
8.0.240.0000.00716.85
8.0.230.0040.00416.91
8.0.220.0070.00016.80
8.0.210.0040.00416.80
8.0.200.0000.00816.97
8.0.190.0040.00416.96
8.0.180.0040.00416.94
8.0.170.0030.00516.96
8.0.160.0050.00316.93
8.0.150.0000.00816.81
8.0.140.0020.00516.80
8.0.130.0030.00313.34
8.0.120.0030.00716.93
8.0.110.0040.00416.93
8.0.100.0040.00416.68
8.0.90.0070.00016.69
8.0.80.0060.00916.95
8.0.70.0000.00716.86
8.0.60.0040.00416.81
8.0.50.0040.00416.85
8.0.30.0130.00717.19
8.0.20.0070.01317.40
8.0.10.0000.00816.93
8.0.00.0120.00916.73
7.4.330.0000.00515.55
7.4.320.0060.00016.52
7.4.300.0030.00316.64
7.4.290.0030.00316.57
7.4.280.0060.00616.49
7.4.270.0000.00716.59
7.4.260.0000.00716.54
7.4.250.0070.00016.50
7.4.240.0030.00316.44
7.4.230.0020.00516.46
7.4.220.0000.00716.51
7.4.210.0060.01016.54
7.4.200.0000.00716.52
7.4.160.0060.01116.49
7.4.130.0100.01416.44
7.4.120.0060.01216.45
7.4.110.0100.00716.75
7.4.100.0100.00716.44
7.4.90.0120.00616.43
7.4.80.0110.01119.39
7.4.70.0030.01516.44
7.4.60.0110.00616.58
7.4.50.0060.00916.67
7.4.40.0120.00516.45
7.4.10.0080.00814.98
7.4.00.0080.00815.09
7.3.330.0000.00513.39
7.3.320.0000.00613.31
7.3.310.0030.00316.23
7.3.300.0050.00216.27
7.3.290.0030.00316.42
7.3.280.0150.00516.36
7.3.260.0120.00716.42
7.3.240.0080.01016.39
7.3.230.0070.01416.31
7.3.210.0110.00616.65
7.3.200.0090.00916.57
7.3.190.0130.00616.67
7.3.180.0100.00716.49
7.3.170.0090.00916.29
7.3.160.0050.01316.64
7.3.130.0020.01614.86
7.3.120.0050.01114.97
7.3.110.0100.00914.74
7.3.100.0090.00514.54
7.3.90.0050.01114.92
7.3.80.0070.00714.86
7.3.70.0120.00214.80
7.3.60.0070.00514.63
7.3.50.0030.00814.90
7.3.40.0090.00214.78
7.3.30.0050.01014.93
7.3.20.0320.00815.61
7.3.10.0220.00515.90
7.3.00.0220.00615.99
7.2.330.0030.01416.76
7.2.320.0120.00416.63
7.2.310.0110.00716.79
7.2.300.0160.00016.59
7.2.290.0120.00616.68
7.2.260.0090.01015.04
7.2.250.0050.01115.25
7.2.240.0050.01015.31
7.2.230.0060.01115.11
7.2.220.0040.01614.81
7.2.210.0060.00815.01
7.2.200.0060.00914.88
7.2.190.0110.00515.07
7.2.180.0060.01015.12
7.2.170.0040.01115.12
7.2.160.0030.00814.98
7.2.150.0260.00216.04
7.2.140.0230.00516.25
7.2.130.0210.00816.24
7.2.120.0210.00416.20
7.2.110.0260.00816.35
7.2.100.0280.00916.25
7.2.90.0290.00816.34
7.2.80.0220.00816.40
7.2.70.0210.00416.32
7.2.60.0190.00716.21
7.2.50.0280.01016.37
7.2.40.0370.01016.23
7.2.30.0050.01116.35
7.2.20.0180.00616.16
7.2.10.0250.00816.27
7.2.00.0220.00816.42
7.1.330.0070.00515.85
7.1.320.0060.00815.73
7.1.310.0070.00515.94
7.1.300.0050.00815.61
7.1.290.0070.00315.75
7.1.280.0060.00815.80
7.1.270.0040.00515.62
7.1.260.0050.00615.74
7.1.250.0040.01015.09
7.1.240.0040.00815.68
7.1.230.0080.00315.96
7.1.220.0050.00915.79
7.1.210.0050.00615.85
7.1.200.0060.00815.79
7.1.190.0020.01115.70
7.1.180.0110.00215.77
7.1.170.0040.00715.68
7.1.160.0070.00615.85
7.1.150.0050.00515.68
7.1.140.0030.01015.79
7.1.130.0070.00515.96
7.1.120.0060.00815.79
7.1.110.0050.00815.95
7.1.100.0060.00515.98
7.1.90.0060.00715.81
7.1.80.0040.00915.92
7.1.70.0050.00915.80
7.1.60.0060.00815.82
7.1.50.0050.00715.93
7.1.40.0070.00515.85
7.1.30.0090.00615.83
7.1.20.0060.00715.89
7.1.10.0040.01115.70
7.1.00.0080.00515.85

preferences:
28.22 ms | 401 KiB | 5 Q