3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public static function validateUPCA($value) { $upc = strval($value); $stringLength = strlen($upc); if($stringLength < 12 || $stringLength > 13 || intval($upc)==0) { return false; } $odd_sum = 0; $even_sum = 0; for($i = 0; $i < $stringLength - 1; $i++) { if($i % 2 === 1) { $even_sum += $upc[$i]; } else { $odd_sum += $upc[$i]; } } if ($stringLength == 12) { // UPC-A format. Odd Sum * 3 $total_sum = $even_sum + $odd_sum * 3; } else { // EAN format. Even Sum * 3 $total_sum = $odd_sum + $even_sum * 3; } $modulo10 = $total_sum % 10; $check_digit = $modulo10 == 0 ? 0 : 10 - $modulo10; return $upc[$stringLength - 1] == $check_digit; } } $res = Test.validateUPCA(840018115309); echo "res: $res\n";

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.0060.01216.75
8.3.50.0180.00522.11
8.3.40.0090.00618.86
8.3.30.0070.00718.67
8.3.20.0000.00720.34
8.3.10.0080.00023.66
8.3.00.0060.00319.38
8.2.180.0040.01118.66
8.2.170.0070.01422.96
8.2.160.0140.00719.47
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0000.00817.50
8.2.120.0040.00426.35
8.2.110.0100.00020.83
8.2.100.0080.00417.91
8.2.90.0030.00517.90
8.2.80.0000.00817.97
8.2.70.0030.00617.63
8.2.60.0040.00417.80
8.2.50.0000.00818.07
8.2.40.0060.00319.21
8.2.30.0040.00420.52
8.2.20.0040.00717.80
8.2.10.0070.00018.12
8.2.00.0000.00718.09
8.1.280.0070.00725.92
8.1.270.0040.00423.91
8.1.260.0070.00028.09
8.1.250.0040.00428.09
8.1.240.0110.00020.74
8.1.230.0110.00020.89
8.1.220.0040.00417.74
8.1.210.0000.00818.96
8.1.200.0100.00017.23
8.1.190.0000.00917.23
8.1.180.0030.00618.10
8.1.170.0060.00318.37
8.1.160.0000.00722.02
8.1.150.0000.00718.82
8.1.140.0000.00819.51
8.1.130.0000.00717.69
8.1.120.0100.00017.30
8.1.110.0000.00717.32
8.1.100.0000.00817.37
8.1.90.0070.00017.42
8.1.80.0030.00317.41
8.1.70.0080.00017.35
8.1.60.0030.00617.56
8.1.50.0060.00317.46
8.1.40.0000.00817.46
8.1.30.0050.00317.64
8.1.20.0000.00817.43
8.1.10.0030.00617.38
8.1.00.0030.00517.38
8.0.300.0040.00419.98
8.0.290.0070.00016.75
8.0.280.0030.00318.51
8.0.270.0040.00417.17
8.0.260.0000.00617.27
8.0.250.0030.00317.07
8.0.240.0030.00317.04
8.0.230.0070.00016.93
8.0.220.0000.00716.99
8.0.210.0100.00016.83
8.0.200.0030.00317.04
8.0.190.0000.00817.03
8.0.180.0000.00716.97
8.0.170.0040.00417.02
8.0.160.0000.00717.01
8.0.150.0050.00316.79
8.0.140.0000.00816.79
8.0.130.0060.00013.42
8.0.120.0080.00016.93
8.0.110.0040.00416.82
8.0.100.0040.00416.86
8.0.90.0000.00716.90
8.0.80.0040.01117.00
8.0.70.0000.00716.92
8.0.60.0070.00016.76
8.0.50.0000.00816.78
8.0.30.0080.01017.03
8.0.20.0080.01117.40
8.0.10.0040.00416.89
8.0.00.0070.01016.71
7.4.330.0020.00216.84
7.4.320.0030.00316.50
7.4.300.0000.00716.39
7.4.290.0070.00016.35
7.4.280.0030.00516.45
7.4.270.0000.00716.55
7.4.260.0080.00016.46
7.4.250.0000.00716.38
7.4.240.0000.00716.53
7.4.230.0030.00316.36
7.4.220.0160.00316.57
7.4.210.0100.00716.57
7.4.200.0000.00716.39
7.4.160.0120.00616.71
7.4.150.0100.00717.40
7.4.140.0130.00517.86
7.4.130.0080.01216.48
7.4.120.0080.01416.65
7.4.110.0100.00716.36
7.4.100.0030.01416.39
7.4.90.0120.00616.34
7.4.80.0030.01419.39
7.4.70.0030.02016.67
7.4.60.0100.00716.67
7.4.50.0070.01016.46
7.4.40.0060.00916.25
7.4.30.0100.01016.68
7.4.00.0110.00015.03
7.3.330.0040.00213.13
7.3.320.0000.00513.28
7.3.310.0000.00716.34
7.3.300.0000.00716.21
7.3.290.0030.01116.31
7.3.280.0100.00716.28
7.3.270.0100.01017.40
7.3.260.0200.00316.35
7.3.250.0100.00716.26
7.3.240.0110.00616.41
7.3.230.0110.00716.55
7.3.210.0140.00516.63
7.3.200.0100.00716.44
7.3.190.0090.00916.44
7.3.180.0110.00516.52
7.3.170.0120.00416.48
7.3.160.0140.00716.49
7.2.330.0040.01416.54
7.2.320.0060.01016.80
7.2.310.0090.01316.54
7.2.300.0060.01116.37
7.2.290.0120.00916.57
7.2.60.0030.01417.00
7.2.00.0030.00819.18
7.1.200.0030.00715.79
7.1.100.0070.00718.22
7.1.70.0000.01017.03
7.1.60.0070.01719.48
7.1.50.0070.01316.92
7.1.00.0030.07722.40
7.0.200.0150.00916.68
7.0.60.0100.07020.09
7.0.50.0030.07317.88
7.0.40.0070.05720.18
7.0.30.0230.03720.15
7.0.20.0170.07720.10
7.0.10.0070.08720.15
7.0.00.0130.07720.23
5.6.280.0030.05020.82
5.6.210.0130.06720.55
5.6.200.0100.08018.29
5.6.190.0100.08320.47
5.6.180.0300.07720.33
5.6.170.0370.05720.69
5.6.160.0030.05320.56
5.6.150.0070.05318.18
5.6.140.0000.04718.24
5.6.130.0070.07018.15
5.6.120.0100.08321.02
5.6.110.0130.03020.98
5.6.100.0200.06020.98
5.6.90.0070.04021.03
5.6.80.0100.07720.39
5.5.350.4330.03720.41
5.5.340.0070.07018.02
5.5.330.0130.07720.19
5.5.320.0070.08020.38
5.5.310.0270.07320.30
5.5.300.0070.08018.09
5.5.290.0070.05017.95
5.5.280.0000.04320.87
5.5.270.0030.04720.79
5.5.260.0130.08020.82
5.5.250.0030.08720.67
5.5.240.0370.06320.27

preferences:
56.11 ms | 401 KiB | 5 Q