3v4l.org

run code in 300+ PHP versions simultaneously
<?php $amount = $qty = $code = $id = range(1, 5000); //dry run to cache function calls $op = '%s executed in %.8f seconds'; microtime(true); $max = count($id); $start = $end = 0; $data = []; for ($i=0; $i<$max; $i++) { $data[] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $data = []; foreach($id as $i => $v) { $data[$i] = [ 'id' => $v, 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $data = array_map(function($a, $b, $c, $d) { return [ 'id' => $a, 'code' => $b, 'qty' => $c, 'amount' => $d ]; }, $id, $code, $qty, $amount); //end dry-run $start = microtime(true); $data = []; foreach($id as $i => $v) { $data[] = [ 'id' => $v, 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $end = microtime(true); printf($op, 'foreach', $end - $start); echo PHP_EOL; //---- $start = microtime(true); $max = count($id); $data = []; for ($i=0; $i<$max; $i++) { $data[] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $end = microtime(true); printf($op, 'for', $end - $start); echo PHP_EOL; $start = microtime(true); $data = array_map(function($a, $b, $c, $d) { return [ 'id' => $a, 'code' => $b, 'qty' => $c, 'amount' => $d ]; }, $id, $code, $qty, $amount); $end = microtime(true); printf($op, 'array_map', $end - $start);

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.0130.01520.28
7.4.00.0080.02020.29
7.3.130.0090.01720.14
7.3.120.0100.01720.27
7.3.110.0200.00620.08
7.3.100.0120.01520.13
7.3.90.0150.01120.11
7.3.80.0160.01020.28
7.3.70.0150.01420.20
7.3.60.0140.01420.17
7.3.50.0150.01220.03
7.3.40.0110.01620.24
7.3.30.0180.01220.15
7.3.20.0140.01320.13
7.3.10.0130.01420.13
7.3.00.0100.01820.15
7.2.260.0170.01220.43
7.2.250.0080.01920.32
7.2.240.0160.01020.37
7.2.230.0080.02020.31
7.2.220.0060.02220.60
7.2.210.0160.01120.47
7.2.200.0070.02220.50
7.2.190.0120.01820.37
7.2.180.0110.01620.44
7.2.170.0080.02020.36
7.2.160.0130.01320.50
7.2.150.0100.01820.49
7.2.140.0170.01520.39
7.2.130.0140.01820.58
7.2.120.0380.01720.62
7.2.110.0100.02520.53
7.2.100.0180.01320.51
7.2.90.0160.01420.50
7.2.80.0150.01820.44
7.2.70.0200.01420.42
7.2.60.0130.01920.48
7.2.50.0100.01920.53
7.2.40.0150.01620.64
7.2.30.0140.01520.52
7.2.20.0190.01120.53
7.2.10.0130.01620.49
7.2.00.0140.01620.39
7.1.330.0240.01219.51
7.1.320.0220.02319.60
7.1.310.0210.01619.59
7.1.300.0110.02319.44
7.1.290.0080.02619.34
7.1.280.0310.01219.60
7.1.270.0220.01219.54
7.1.260.0240.01219.52
7.1.250.0180.01419.50
7.1.240.0170.02319.39
7.1.230.0150.01919.38
7.1.220.0170.02319.45
7.1.210.0250.01619.59
7.1.200.0360.02319.28
7.1.190.0220.01719.44
7.1.180.0270.01519.50
7.1.170.0270.01719.41
7.1.160.0360.01519.35
7.1.150.0200.01419.32
7.1.140.0220.01519.52
7.1.130.0150.02719.50
7.1.120.0380.01019.54
7.1.110.0190.01919.65
7.1.100.0160.02019.60
7.1.90.0180.02119.41
7.1.80.0120.02419.51
7.1.70.0120.02419.35
7.1.60.0260.01819.48
7.1.50.0160.02219.42
7.1.40.0150.01819.46
7.1.30.0260.01319.46
7.1.20.0260.01019.40
7.1.10.0310.03119.47
7.1.00.0290.01219.24
7.0.330.0150.01819.17
7.0.320.0250.01819.19
7.0.310.0140.02019.12
7.0.300.0160.02319.01
7.0.290.0200.01719.21
7.0.280.0140.01719.33
7.0.270.0150.01919.41
7.0.260.0220.01619.29
7.0.250.0120.02419.33
7.0.240.0180.01719.25
7.0.230.0080.03319.27
7.0.220.0260.01519.14
7.0.210.0200.02019.03
7.0.200.0210.01419.23
7.0.190.0180.01919.11
7.0.180.0190.02019.35
7.0.170.0150.02319.24
7.0.160.0230.01719.15
7.0.150.0180.02019.23
7.0.140.0160.02219.36
7.0.130.0230.01419.19
7.0.120.0210.01419.14
7.0.110.0190.01619.19
7.0.100.0230.02219.35
7.0.90.0250.01219.11
7.0.80.0350.01919.17
7.0.70.0230.02019.35
7.0.60.0190.01619.33
7.0.50.0160.01919.13
7.0.40.0270.01719.18
7.0.30.0220.01819.19
7.0.20.0130.02319.22
7.0.10.0270.02019.18
7.0.00.0220.01818.88
5.6.400.0230.04024.98
5.6.390.0180.06125.30
5.6.380.0290.05924.94
5.6.370.0350.07024.98
5.6.360.0310.05025.18
5.6.350.0150.05725.37
5.6.340.0350.03925.22
5.6.330.0350.05125.26
5.6.320.0360.04325.14
5.6.310.0200.05525.07
5.6.300.0300.05024.89
5.6.290.0220.05325.24
5.6.280.0140.07025.28
5.6.270.0270.05325.09
5.6.260.0410.04524.84
5.6.250.0490.04325.02
5.6.240.0230.06925.31
5.6.230.0200.07025.10
5.6.220.0230.05524.95
5.6.210.0350.05624.98
5.6.200.0260.04425.05
5.6.190.0190.05625.02
5.6.180.0280.05324.88
5.6.170.0170.07225.00
5.6.160.0330.06025.18
5.6.150.0410.04124.88
5.6.140.0310.04925.02
5.6.130.0410.06125.01
5.6.120.0240.05024.84
5.6.110.0360.05725.06
5.6.100.0270.04924.95
5.6.90.0310.04425.06
5.6.80.0240.04624.93
5.6.70.0300.04625.02
5.6.60.0310.04124.79
5.6.50.0240.04924.59
5.6.40.0180.05424.86
5.6.30.0250.05024.99
5.6.20.0160.05925.05
5.6.10.0380.03524.82
5.6.00.0240.04524.92
5.5.380.0450.06324.95
5.5.370.0210.05325.01
5.5.360.0320.05524.84
5.5.350.0260.04524.92
5.5.340.0250.05524.91
5.5.330.0280.05825.10
5.5.320.0380.05425.04
5.5.310.0280.05525.19
5.5.300.0200.06625.16
5.5.290.0500.06625.07
5.5.280.0350.04925.07
5.5.270.0200.06624.84
5.5.260.0290.04725.23
5.5.250.0290.04224.88
5.5.240.0260.04524.77
5.5.230.0190.05725.02
5.5.220.0340.04424.88
5.5.210.0200.05424.83
5.5.200.0260.04724.80
5.5.190.0240.04824.71
5.5.180.0280.04624.94
5.5.170.0330.04925.06
5.5.160.0140.07025.02
5.5.150.0350.06625.05
5.5.140.0400.03724.98
5.5.130.0330.06324.99
5.5.120.0310.06325.16
5.5.110.0370.07024.80
5.5.100.0360.05324.99
5.5.90.0260.04824.89
5.5.80.0230.04925.02
5.5.70.0380.05324.93
5.5.60.0300.04324.96
5.5.50.0310.04124.95
5.5.40.0200.04824.98
5.5.30.0250.04524.90
5.5.20.0330.03624.88
5.5.10.0250.05124.98
5.5.00.0300.05024.84
5.4.450.0230.04621.73
5.4.440.0170.05121.92
5.4.430.0340.03521.91
5.4.420.0270.03921.63
5.4.410.0220.03921.76
5.4.400.0280.06621.64
5.4.390.0170.04821.77
5.4.380.0210.04621.54
5.4.370.0280.03521.80
5.4.360.0420.04321.71
5.4.350.0230.04221.70
5.4.340.0140.05121.85
5.4.330.0260.04921.70
5.4.320.0240.04621.79
5.4.310.0260.04221.79
5.4.300.0330.06321.83
5.4.290.0300.03621.68
5.4.280.0260.04021.76
5.4.270.0250.04221.68
5.4.260.0210.04321.64
5.4.250.0190.04921.76
5.4.240.0210.07121.64
5.4.230.0190.06821.68
5.4.220.0320.03021.77
5.4.210.0220.04421.67
5.4.200.0220.04021.73
5.4.190.0240.04121.63
5.4.180.0240.07821.63
5.4.170.0300.04021.80
5.4.160.0220.04421.85
5.4.150.0180.05021.73
5.4.140.0280.03521.90
5.4.130.0260.03921.66
5.4.120.0180.05121.73
5.4.110.0130.04921.67
5.4.100.0300.04021.55
5.4.90.0390.02521.84
5.4.80.0270.05221.82
5.4.70.0210.04221.63
5.4.60.0180.04421.78
5.4.50.0220.05821.74
5.4.40.0340.04121.63
5.4.30.0320.03321.84
5.4.20.0210.04621.61
5.4.10.0210.04321.41
5.4.00.0240.03821.48
5.3.290.0150.00412.74
5.3.280.0080.00812.71
5.3.270.0090.00612.59
5.3.260.0120.00912.86
5.3.250.0080.00612.93
5.3.240.0100.00312.69
5.3.230.0100.00712.70
5.3.220.0040.01212.54
5.3.210.0040.01212.52
5.3.200.0120.00212.53
5.3.190.0080.00812.78
5.3.180.0060.01012.70
5.3.170.0060.00912.91
5.3.160.0070.01413.04
5.3.150.0100.00813.03
5.3.140.0030.01312.63
5.3.130.0090.00912.69
5.3.120.0090.01212.68
5.3.110.0090.00912.74
5.3.100.0080.00712.62
5.3.90.0070.00712.75
5.3.80.0090.00612.70
5.3.70.0030.01212.76
5.3.60.0070.01112.74
5.3.50.0030.01812.67
5.3.40.0060.01212.62
5.3.30.0100.01012.58
5.3.20.0120.00812.69
5.3.10.0090.00912.48
5.3.00.0050.01012.40
5.2.170.0030.01311.83
5.2.160.0080.00511.83
5.2.150.0030.01411.88
5.2.140.0040.01111.93
5.2.130.0030.00911.83
5.2.120.0110.00311.83
5.2.110.0060.00611.83
5.2.100.0000.01211.83
5.2.90.0060.00611.83
5.2.80.0060.00611.83
5.2.70.0030.00911.83
5.2.60.0060.00611.83
5.2.50.0170.01211.83
5.2.40.0070.01011.83
5.2.30.0040.01411.83
5.2.20.0130.00311.83
5.2.10.0030.01211.83
5.2.00.0060.00911.83
5.1.60.0060.00911.83
5.1.50.0040.00911.83
5.1.40.0090.00311.83
5.1.30.0080.00411.83
5.1.20.0030.01011.83
5.1.10.0000.01411.83
5.1.00.0130.00311.83
5.0.50.0070.00211.83
5.0.40.0060.00311.83
5.0.30.0030.01011.83
5.0.20.0030.00711.83
5.0.10.0000.00911.83
5.0.00.0060.00311.83
4.4.90.0060.00011.83
4.4.80.0060.00011.83
4.4.70.0000.00811.83
4.4.60.0050.00311.83
4.4.50.0000.00611.83
4.4.40.0030.00311.83
4.4.30.0050.00211.83
4.4.20.0000.00611.83
4.4.10.0030.00311.83
4.4.00.0000.00511.83
4.3.110.0060.00011.83
4.3.100.0040.00211.83
4.3.90.0000.00711.83
4.3.80.0000.00611.83
4.3.70.0000.00511.83
4.3.60.0000.00511.83
4.3.50.0050.00011.83
4.3.40.0060.00011.83
4.3.30.0040.00811.83
4.3.20.0030.00311.83
4.3.10.0060.00011.83
4.3.00.0050.00011.83

preferences:
28.67 ms | 403 KiB | 5 Q