3v4l.org

run code in 300+ PHP versions simultaneously
<?php function bc() { $argv = func_get_args(); $string = str_replace(' ', '', "({$argv[0]})"); $operations = array(); if (strpos($string, '^') !== false) $operations[] = '\^'; if (strpbrk($string, '*/%') !== false) $operations[] = '[\*\/\%]'; if (strpbrk($string, '+-') !== false) $operations[] = '[\+\-]'; if (strpbrk($string, '<>!=') !== false) $operations[] = '<|>|=|<=|==|>=|!=|<>'; $string = preg_replace('/\$([0-9\.]+)/e', '$argv[$1]', $string); while (preg_match('/\(([^\)\(]*)\)/', $string, $match)) { foreach ($operations as $operation) { if (preg_match("/([+-]{0,1}[0-9\.]+)($operation)([+-]{0,1}[0-9\.]+)/", $match[1], $m)) { switch($m[2]) { case '+': $result = bcadd($m[1], $m[3]); break; case '-': $result = bcsub($m[1], $m[3]); break; case '*': $result = bcmul($m[1], $m[3]); break; case '/': $result = bcdiv($m[1], $m[3]); break; case '%': $result = bcmod($m[1], $m[3]); break; case '^': $result = bcpow($m[1], $m[3]); break; case '==': case '=': $result = bccomp($m[1], $m[3]) == 0; break; case '>': $result = bccomp($m[1], $m[3]) == 1; break; case '<': $result = bccomp($m[1], $m[3]) == -1; break; case '>=': $result = bccomp($m[1], $m[3]) >= 0; break; case '<=': $result = bccomp($m[1], $m[3]) <= 0; break; case '<>': case '!=': $result = bccomp($m[1], $m[3]) != 0; break; } $match[1] = str_replace($m[0], $result, $match[1]); } } $string = str_replace($match[0], $match[1], $string); } return $string; } // Exemplo de uso: Operações matemáticas $resultado = bc("(2 + 3) * 4"); echo $resultado; // Saída: 20

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.5.30.0090.00919.77
8.5.20.0120.00618.34
8.5.10.0140.00617.07
8.5.00.0130.00717.37
8.4.180.0140.00820.15
8.4.170.0110.01024.01
8.4.160.0130.01023.50
8.4.150.0310.00920.11
8.4.140.0340.00918.14
8.4.130.0250.00817.91
8.4.120.0380.00618.24
8.4.110.0360.00918.18
8.4.100.0200.00518.31
8.4.90.0350.01018.20
8.4.80.0360.01018.20
8.4.70.0360.00918.11
8.4.60.0250.00518.22
8.4.50.0350.00618.32
8.4.40.0440.00818.11
8.4.30.0260.00217.89
8.4.20.0180.00418.17
8.4.10.0220.00517.75
8.3.300.0100.01020.93
8.3.290.0110.00922.50
8.3.280.0160.00818.65
8.3.270.0280.00817.37
8.3.260.0340.00617.37
8.3.250.0320.00917.37
8.3.240.0290.00517.37
8.3.230.0350.00817.37
8.3.220.0310.00517.37
8.3.210.0270.01217.37
8.3.200.0200.00617.37
8.3.190.0170.00317.37
8.3.180.0140.00517.37
8.3.170.0270.00617.37
8.3.160.0360.00817.37
8.3.150.0350.00917.37
8.3.140.0330.00417.37
8.3.130.0240.00517.37
8.3.120.0300.00817.37
8.3.110.0380.00917.37
8.3.100.0350.00717.37
8.3.90.0360.00417.37
8.3.80.0320.00517.37
8.3.70.0290.00717.37
8.3.60.0340.00917.37
8.3.50.0450.00717.37
8.3.40.0320.00818.29
8.3.30.0300.00718.20
8.3.20.0280.01118.27
8.3.10.0260.01018.29
8.3.00.0220.00818.13
8.2.300.0070.01318.32
8.2.290.0280.01017.37
8.2.280.0300.00717.37
8.2.270.0200.00617.37
8.1.340.0080.01317.99

preferences:
40.47 ms | 403 KiB | 5 Q