3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mergeAttachments($a, $b) { // If both #attached arrays contain drupalSettings, then merge them // correctly; adding the same settings multiple times needs to behave // idempotently. if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) { $drupalSettings = mergeDeepArray(array($a['drupalSettings'], $b['drupalSettings']), TRUE); // No need for re-merging them. unset($a['drupalSettings']); unset($b['drupalSettings']); } // Apply the normal merge. $a = mergeDeepArray(array($a, $b)); if (isset($drupalSettings)) { // Save the custom merge for the drupalSettings. $a['drupalSettings'] = $drupalSettings; } return $a; } function mergeAttachmentsOld($a, $b) { if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) { $a['drupalSettings'] = mergeDeepArray([$a['drupalSettings'], $b['drupalSettings']], TRUE); unset($b['drupalSettings']); } return mergeDeep($a, $b); } function mergeDeepArray($arrays, $preserve_integer_keys = FALSE) { $result = array(); foreach ($arrays as $array) { foreach ($array as $key => $value) { // Renumber integer keys as array_merge_recursive() does unless // $preserve_integer_keys is set to TRUE. Note that PHP automatically // converts array keys that are integer strings (e.g., '1') to integers. if (is_integer($key) && !$preserve_integer_keys) { $result[] = $value; } // Recurse when both values are arrays. elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) { $result[$key] = mergeDeepArray(array($result[$key], $value), $preserve_integer_keys); } // Otherwise, use the latter value, overriding any previous value. else { $result[$key] = $value; } } } return $result; } function mergeDeep() { return mergeDeepArray(func_get_args()); } for($i = 0; $i <= 100000; $i++) { $a['#attached'] = array( 'library' => array( 'core/drupal', 'core/drupalSettings', ), ); $b['#attached'] = array( 'library' => array( 'core/jquery', ), ); mergeAttachments($a['#attached'], $b['#attached']); }

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.60.0070.09516.74
8.3.50.0150.08821.97
8.3.40.0030.08218.67
8.3.30.0170.08319.04
8.3.20.0000.04520.29
8.3.10.0070.03821.73
8.3.00.0090.03520.96
8.2.180.0130.07618.37
8.2.170.0130.07122.96
8.2.160.0070.07622.04
8.2.150.0030.04324.18
8.2.140.0040.04224.66
8.2.130.0030.04326.16
8.2.120.0030.05218.16
8.2.110.0100.08719.25
8.2.100.0030.08117.63
8.2.90.0060.06419.40
8.2.80.0000.07117.97
8.2.70.0000.07317.63
8.2.60.0100.06317.93
8.2.50.0070.07518.07
8.2.40.0030.06619.79
8.2.30.0070.07118.15
8.2.20.0000.07117.83
8.2.10.0030.06918.03
8.2.00.0030.07017.75
8.1.280.0100.09925.92
8.1.270.0070.04220.53
8.1.260.0040.04226.35
8.1.250.0060.03928.09
8.1.240.0030.08423.97
8.1.230.0060.06817.42
8.1.220.0030.06817.77
8.1.210.0030.07318.77
8.1.200.0030.07817.35
8.1.190.0030.06917.35
8.1.180.0070.07318.10
8.1.170.0000.06718.68
8.1.160.0070.05921.92
8.1.150.0030.06818.90
8.1.140.0070.07319.15
8.1.130.0000.06917.90
8.1.120.0030.06917.41
8.1.110.0070.06717.47
8.1.100.0000.07217.46
8.1.90.0000.07217.55
8.1.80.0000.07017.44
8.1.70.0000.07317.46
8.1.60.0030.07817.59
8.1.50.0030.07717.40
8.1.40.0000.08017.41
8.1.30.0030.07817.57
8.1.20.0000.08017.61
8.1.10.0030.07917.52
8.1.00.0030.09617.53
8.0.300.0030.06818.77
8.0.290.0070.06916.63
8.0.280.0000.07818.48
8.0.270.0000.07417.28
8.0.260.0030.07717.35
8.0.250.0060.06817.02
8.0.240.0030.08616.98
8.0.230.0030.07016.87
8.0.220.0000.07616.98
8.0.210.0070.06916.85
8.0.200.0030.07216.96
8.0.190.0100.07216.91
8.0.180.0030.07716.80
8.0.170.0030.07916.96
8.0.160.0030.07717.01
8.0.150.0030.07716.81
8.0.140.0000.08016.79
8.0.130.0060.07113.31
8.0.120.0030.08016.87
8.0.110.0030.07616.91
8.0.100.0100.07616.72
8.0.90.0030.07716.79
8.0.80.0070.10316.81
8.0.70.0100.07016.93
8.0.60.0030.07616.95
8.0.50.0070.07416.75
8.0.30.0130.12517.14
8.0.20.0140.11417.40
8.0.10.0000.08017.06
8.0.00.0080.17916.80
7.4.330.0000.07515.03
7.4.320.0030.07316.68
7.4.300.0000.07816.55
7.4.290.0060.07516.39
7.4.280.0000.08316.60
7.4.270.0000.08216.64
7.4.260.0070.07716.59
7.4.250.0030.08016.57
7.4.240.0050.07816.53
7.4.230.0000.08116.58
7.4.220.0130.12116.61
7.4.210.0160.16316.57
7.4.200.0030.07816.56
7.4.160.0030.11116.57
7.4.150.0090.15717.40
7.4.140.0080.15117.86
7.4.130.0090.12716.60
7.4.120.0110.10816.53
7.4.110.0070.11316.67
7.4.100.0120.14116.57
7.4.90.0160.17816.45
7.4.80.0070.14016.34
7.4.70.0100.11916.46
7.4.60.0070.11816.46
7.4.50.0030.05616.53
7.4.40.0160.10816.39
7.4.30.0090.18916.59
7.4.00.0030.13015.08
7.3.330.0000.09113.27
7.3.320.0070.08713.19
7.3.310.0000.08516.21
7.3.300.0030.08116.28
7.3.290.0100.12116.38
7.3.280.0090.15416.37
7.3.270.0070.12417.40
7.3.260.0070.11916.41
7.3.250.0100.11616.60
7.3.240.0100.13716.32
7.3.230.0100.11716.46
7.3.210.0160.10616.71
7.3.200.0170.16419.39
7.3.190.0130.19016.59
7.3.180.0130.12416.29
7.3.170.0070.13016.59
7.3.160.0130.11716.61
7.2.330.0130.12116.82
7.2.320.0070.19716.87
7.2.310.0130.17016.89
7.2.300.0100.14116.46
7.2.290.0060.13016.75
7.2.60.0000.08017.05
7.2.00.0000.08119.43
7.1.200.0030.07615.91
7.1.100.0000.11618.28
7.1.70.0030.09017.25
7.1.60.0030.15019.46
7.1.50.0100.10416.79
7.1.00.0070.18722.32
7.0.200.0160.08314.76
7.0.140.0030.13722.08
7.0.60.0130.17319.98
7.0.50.0030.15717.74
7.0.40.0000.13020.11
7.0.30.0330.14720.34
7.0.20.0100.13020.13
7.0.10.0070.16720.24
7.0.00.0070.17720.10
5.6.210.0130.36320.68
5.6.200.0030.34718.22
5.6.190.0100.39720.41
5.6.180.4170.35320.52
5.6.170.0170.34020.47
5.6.160.0100.36720.54
5.6.150.0070.37018.19
5.6.140.0130.37718.28
5.6.130.0000.33718.15
5.6.120.0030.40021.08
5.6.110.0070.32321.01
5.6.100.0070.40720.99
5.6.90.0000.38321.09
5.6.80.0100.37320.34
5.6.70.3330.28720.39
5.5.350.0270.30320.48
5.5.340.0070.38718.09
5.5.330.0130.42720.37
5.5.320.0330.42320.29
5.5.310.0130.36720.24
5.5.300.0070.43317.95
5.5.290.0030.42317.98
5.5.280.0070.44320.66
5.5.270.0270.39320.88
5.5.260.0130.42720.77
5.5.250.0170.42320.59
5.5.240.0270.41320.37
5.4.450.0630.62319.57
5.4.440.0700.63719.58
5.4.430.0900.71719.57
5.4.420.0830.63719.46
5.4.410.0730.62019.34
5.4.400.0970.64719.40
5.4.390.0130.83318.79
5.4.380.0330.87318.80
5.4.370.0230.80318.80
5.4.360.0170.70318.71
5.4.350.0100.80018.72
5.4.340.0230.74018.59
5.4.320.0300.75018.51
5.4.310.0130.78318.52
5.4.300.0170.77718.78
5.4.290.0300.71318.78
5.4.280.0270.92718.80
5.4.270.0300.82318.49
5.4.260.0231.00318.77
5.4.250.0330.73718.83
5.4.240.0230.80318.80
5.4.230.0170.73318.79
5.4.220.0100.74318.70
5.4.210.0230.72318.83
5.4.200.0200.81716.54
5.4.190.0200.81018.79
5.4.180.0100.87718.76
5.4.170.0170.79718.55
5.4.160.0330.70718.75
5.4.150.0230.78318.44
5.4.140.0170.71016.21
5.4.130.0130.75316.21
5.4.120.0270.68716.25
5.4.110.0100.70016.33
5.4.100.0070.93716.33
5.4.90.0170.69016.29
5.4.80.0170.75316.44
5.4.70.0170.78316.17
5.4.60.0070.62016.16
5.4.50.0170.77016.21
5.4.40.0300.72316.43
5.4.30.0070.83316.21
5.4.20.0100.71316.39
5.4.10.0170.69316.30
5.4.00.0130.68015.75
5.3.290.0200.05314.86
5.3.280.0270.05714.80
5.3.270.0100.06314.77
5.3.260.0230.06714.63
5.3.250.0170.06714.62
5.3.240.0300.04714.73
5.3.230.0170.06014.73
5.3.220.0070.06314.74
5.3.210.0230.05014.61
5.3.200.0170.05014.78
5.3.190.0130.05314.70
5.3.180.0230.04714.56
5.3.170.0200.06014.60
5.3.160.0200.04714.58
5.3.150.0170.06014.61
5.3.140.0230.04714.58
5.3.130.0200.06314.60
5.3.120.0130.07714.68
5.3.110.0100.06014.57
5.3.100.0130.06714.09
5.3.90.0230.04714.00
5.3.80.0200.05014.13
5.3.70.0200.04714.14
5.3.60.0100.06314.00
5.3.50.0170.05714.06
5.3.40.0230.04714.03
5.3.30.0130.05014.01
5.3.20.0130.05313.81
5.3.10.0130.04713.73
5.3.00.0230.05013.68
5.2.170.0130.04011.21
5.2.160.0130.05011.18
5.2.150.0170.05011.26
5.2.140.0130.04311.26
5.2.130.0070.05311.17
5.2.120.0200.05011.11
5.2.110.0170.05711.17
5.2.100.0130.05311.12
5.2.90.0130.04311.16
5.2.80.0070.05711.21
5.2.70.0170.04711.13
5.2.60.0170.04311.04
5.2.50.0070.05011.07
5.2.40.0100.04311.13
5.2.30.0170.04710.98
5.2.20.0130.04711.07
5.2.10.0130.04010.91
5.2.00.0130.03710.71
5.1.60.0030.04310.00
5.1.50.0170.03310.04
5.1.40.0130.04010.03
5.1.30.0030.04710.52
5.1.20.0130.05010.49
5.1.10.0130.03310.12
5.1.00.0100.05010.27
5.0.50.0100.0308.56
5.0.40.0070.0408.49
5.0.30.0030.0478.25
5.0.20.0000.0408.34
5.0.10.0100.0278.22
5.0.00.0000.0508.36
4.4.90.0100.0205.95
4.4.80.0070.0305.88
4.4.70.0130.0235.89
4.4.60.0070.0205.93
4.4.50.0100.0175.95
4.4.40.0070.0336.00
4.4.30.0030.0235.98
4.4.20.0070.0236.06
4.4.10.0030.0236.10
4.4.00.0030.0375.96
4.3.110.0100.0235.83
4.3.100.0200.0205.86
4.3.90.0030.0235.81
4.3.80.0030.0335.89
4.3.70.0030.0235.79
4.3.60.0070.0175.82
4.3.50.0130.0205.81
4.3.40.0070.0435.80
4.3.30.0030.0274.58
4.3.20.0030.0304.53
4.3.10.0000.0304.49
4.3.00.0030.03314.42

preferences:
42.34 ms | 401 KiB | 5 Q