3v4l.org

run code in 300+ PHP versions simultaneously
<?php public 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; } public main() { $value = 840018115309; $res = validateUPCA($value); 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)
5.6.150.0070.07718.15
5.6.140.0100.07318.28
5.6.130.0070.07718.19
5.6.120.0070.07721.03
5.6.110.0070.04321.11
5.6.100.0200.07020.97
5.6.90.0030.04020.98
5.6.80.0030.05720.50
5.5.300.0070.06317.98
5.5.290.0000.05318.02
5.5.280.0070.03720.82
5.5.270.0130.07020.78
5.5.260.0530.05720.73
5.5.250.0030.04320.59
5.5.240.0370.05720.34

preferences:
127.46 ms | 1398 KiB | 7 Q