3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_map_userland_one($callback, array $one) { if ($callback) { // return array_map($callback, $one); echo "- with callback - apply\n"; $return = []; foreach ($one as $key => $value) { $return[$key] = $callback($value); } return $return; } else { // return array_map(function($value) { return $value; }, $one); echo "- without callback - return copy\n"; return $one; } } function array_map_userland_many($callback, array $many) { // for simplicity, assuming non-associative arrays all of the same size if ($callback) { // return array_map($callback, ...$many); echo "- with callback - apply using array of values\n"; $return = []; for ($i = 0; $i < count($many[0]); $i++) { $args = []; foreach ($many as $array) { $args[] = $array[$i]; } $return[$i] = $callback(...$args); } return $return; } else { // return array_map(function(...$values) { return $values; }, ...$many); echo "- without callback - use array of values\n"; $return = []; for ($i = 0; $i < count($many[0]); $i++) { $return[$i] = []; foreach ($many as $array) { $return[$i][] = $array[$i]; } } return $return; } } function array_map_userland($callback, ...$arrays) { if (count($arrays) == 1) { echo "- one array\n"; return array_map_userland_one($callback, $arrays[0]); } else { echo "- many arrays\n"; return array_map_userland_many($callback, $arrays); } } $two_item_array = [["abc", "def"], ["ghi", "jkl"]]; $one_item_array = [["abc", "def"]]; echo "Two arrays:\n"; print_r(array_map_userland(null, ...$two_item_array)); echo "One array:\n"; print_r(array_map_userland(null, ...$one_item_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.60.0120.00616.50
8.3.50.0070.00718.16
8.3.40.0090.00918.97
8.3.30.0030.01318.70
8.3.20.0050.00321.83
8.3.10.0040.00421.95
8.3.00.0080.00020.09
8.2.180.0070.01018.17
8.2.170.0090.00922.96
8.2.160.0090.00920.57
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0030.00620.94
8.2.110.0000.01020.90
8.2.100.0000.01117.84
8.2.90.0090.00019.32
8.2.80.0000.00817.97
8.2.70.0060.00317.63
8.2.60.0000.00918.04
8.2.50.0040.00418.07
8.2.40.0040.00418.35
8.2.30.0000.01018.29
8.2.20.0040.00418.08
8.2.10.0040.00418.07
8.2.00.0050.00317.77
8.1.280.0000.01425.92
8.1.270.0000.00822.02
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0040.00422.64
8.1.230.0060.00619.14
8.1.220.0040.00417.74
8.1.210.0000.00818.77
8.1.200.0030.00617.48
8.1.190.0030.00517.35
8.1.180.0080.00018.10
8.1.170.0000.00818.62
8.1.160.0040.00418.85
8.1.150.0000.00718.93
8.1.140.0000.00719.47
8.1.130.0000.00717.45
8.1.120.0000.00717.44
8.1.110.0030.00517.40
8.1.100.0070.00017.53
8.1.90.0070.00017.49
8.1.80.0040.00417.55
8.1.70.0000.00717.41
8.1.60.0060.00317.66
8.1.50.0040.00417.61
8.1.40.0000.00917.45
8.1.30.0000.00817.68
8.1.20.0000.00817.75
8.1.10.0000.00717.57
8.1.00.0050.00217.54
8.0.300.0050.00318.77
8.0.290.0050.00316.75
8.0.280.0000.00718.50
8.0.270.0040.00417.22
8.0.260.0030.00316.77
8.0.250.0000.00716.93
8.0.240.0050.00316.97
8.0.230.0030.00317.03
8.0.220.0000.00816.97
8.0.210.0000.00716.96
8.0.200.0030.00317.04
8.0.190.0080.00016.99
8.0.180.0070.00016.96
8.0.170.0040.00417.01
8.0.160.0070.00016.94
8.0.150.0040.00416.72
8.0.140.0050.00316.80
8.0.130.0000.00713.35
8.0.120.0040.00416.96
8.0.110.0030.00316.96
8.0.100.0040.00416.80
8.0.90.0040.00417.00
8.0.80.0030.01016.92
8.0.70.0000.00716.93
8.0.60.0000.00816.78
8.0.50.0000.00816.96
8.0.30.0100.01017.22
8.0.20.0100.00917.40
8.0.10.0070.00016.86
8.0.00.0090.00916.95
7.4.330.0050.00015.55
7.4.320.0060.00016.46
7.4.300.0050.00316.47
7.4.290.0030.00316.55
7.4.280.0040.00416.69
7.4.270.0000.00816.57
7.4.260.0030.00616.55
7.4.250.0000.00716.41
7.4.240.0040.00416.63
7.4.230.0000.00716.58
7.4.220.0140.01416.57
7.4.210.0120.00316.73
7.4.200.0030.00316.45
7.4.160.0120.00316.68
7.4.150.0110.00617.40
7.4.140.0130.00617.86
7.4.130.0110.00916.59
7.4.120.0100.00916.50
7.4.110.0180.00416.44
7.4.100.0090.01716.44
7.4.90.0100.00716.70
7.4.80.0100.00719.39
7.4.70.0080.00816.64
7.4.60.0070.01416.49
7.4.50.0040.01116.58
7.4.40.0100.00616.49
7.4.30.0090.01016.71
7.4.00.0080.01014.99
7.3.330.0060.00013.28
7.3.320.0050.00013.34
7.3.310.0000.00716.27
7.3.300.0000.00716.42
7.3.290.0090.00616.42
7.3.280.0060.01216.39
7.3.270.0110.00717.40
7.3.260.0110.00816.69
7.3.250.0090.00916.43
7.3.240.0080.01016.46
7.3.230.0120.00616.64
7.3.210.0100.01416.42
7.3.200.0060.01216.36
7.3.190.0160.00616.50
7.3.180.0110.00516.29
7.3.170.0090.01216.36
7.3.160.0060.01016.62
7.3.120.0090.00915.14
7.3.110.0100.00814.95
7.3.100.0000.01414.95
7.3.90.0060.00815.05
7.3.80.0030.01015.02
7.3.70.0040.00614.80
7.3.60.0030.00814.81
7.3.50.0030.01214.72
7.3.40.0050.00814.70
7.3.30.0090.00714.82
7.3.20.0070.00716.75
7.3.10.0040.01216.67
7.3.00.0070.00716.64
7.2.330.0120.00616.54
7.2.320.0160.00016.52
7.2.310.0100.01316.85
7.2.300.0110.01116.86
7.2.290.0110.00716.75
7.2.250.0060.01114.96
7.2.240.0090.01114.90
7.2.230.0070.00915.30
7.2.220.0080.00214.97
7.2.210.0080.00815.04
7.2.200.0080.00715.19
7.2.190.0030.01315.02
7.2.180.0080.00415.08
7.2.170.0000.01315.10
7.2.130.0140.00016.99
7.2.120.0100.00716.57
7.2.110.0180.00416.89
7.2.100.0070.01116.77
7.2.90.0130.00717.01
7.2.80.0070.01016.62
7.2.70.0110.00716.79
7.2.60.0110.00316.91
7.2.50.0070.01017.02
7.2.40.0060.01216.88
7.2.30.0090.00916.67
7.2.20.0130.00316.96
7.2.10.0130.00316.98
7.2.00.0030.01016.80
7.1.330.0070.00815.84
7.1.320.0080.00415.83
7.1.310.0050.00815.96
7.1.300.0050.00515.81
7.1.290.0060.00615.84
7.1.280.0030.00915.91
7.1.270.0030.00915.93
7.1.260.0090.00315.92
7.1.250.0090.00615.83
7.1.240.0130.00015.90
7.1.230.0040.01215.68
7.1.220.0090.00615.70
7.1.210.0070.01115.65
7.1.200.0130.00715.62
7.1.190.0120.00415.74
7.1.180.0100.00615.49
7.1.170.0100.00715.77
7.1.160.0100.00715.69
7.1.150.0090.00615.75
7.1.140.0110.00315.59
7.1.130.0060.00915.55
7.1.120.0030.00915.62
7.1.110.0080.00415.85
7.1.100.0090.00915.90
7.1.90.0070.00715.87
7.1.80.0070.00715.74
7.1.70.0050.00816.53
7.1.60.0060.00716.49
7.1.50.0140.00615.77
7.1.40.0070.00715.79
7.1.30.0120.00315.69
7.1.20.0130.00015.82
7.1.10.0110.03218.95
7.1.00.0090.03018.93
7.0.330.0100.00715.38
7.0.320.0030.01415.38
7.0.310.0170.00815.10
7.0.300.0120.00614.87
7.0.290.0140.00315.00
7.0.280.0110.00615.15
7.0.270.0120.00315.08
7.0.260.0120.00415.26
7.0.250.0050.00515.50
7.0.240.0030.01015.27
7.0.230.0120.00615.20
7.0.220.0130.00315.23
7.0.210.0130.00315.50
7.0.200.0050.00915.98
7.0.190.0140.00315.15
7.0.180.0100.00615.20
7.0.170.0100.00315.30
7.0.160.0070.01015.16
7.0.150.0120.03018.38
7.0.140.0070.03118.42
7.0.130.0120.02718.57
7.0.120.0030.03418.39
7.0.110.0090.03318.55
7.0.100.0120.02818.60
7.0.90.0110.03018.50
7.0.80.0060.03418.43
7.0.70.0080.03018.38
7.0.60.0050.03718.48
7.0.50.0080.03218.45
7.0.40.0100.02817.49
7.0.30.0100.02817.59
7.0.20.0050.03317.49
7.0.10.0080.03017.57
7.0.00.0110.02617.40
5.6.380.0060.00614.55

preferences:
36.51 ms | 400 KiB | 5 Q