@ 2025-01-19T09:22:31Z <?php
declare(strict_types=1);
error_reporting(E_ALL);
$num1 = new \BcMath\Number('0.12345');
$otherValuesNoFrac = [
'BC' => new \BcMath\Number('2.1'),
'int' => 2,
'float' => 2.1,
'numeric-string' => '2.1',
'non-numeric-string' => 'xyz',
'bool' => true,
'null' => null,
'array' => [],
'object' => new stdClass(),
'resource' => fopen('php://input', 'r'),
'closure' => static fn () => 1,
'generator' => (function () { yield 1; })(),
'stringable' => new class implements Stringable {
public function __toString()
{
return '1.0';
}
},
];
$binaryOps = [
'+' => static fn ($a, $b) => $a + $b,
'-' => static fn ($a, $b) => $a - $b,
'*' => static fn ($a, $b) => $a * $b,
'/' => static fn ($a, $b) => $a / $b,
'%' => static fn ($a, $b) => $a % $b,
'.' => static fn ($a, $b) => $a . $b,
'**' => static fn ($a, $b) => $a ** $b,
'<<' => static fn ($a, $b) => $a << $b,
'>>' => static fn ($a, $b) => $a >> $b,
'<' => static fn ($a, $b) => $a < $b,
'<=' => static fn ($a, $b) => $a <= $b,
'>' => static fn ($a, $b) => $a >=$b,
'>=' => static fn ($a, $b) => $a >= $b,
'<=>' => static fn ($a, $b) => $a <=> $b,
'==' => static fn ($a, $b) => $a == $b,
'!=' => static fn ($a, $b) => $a != $b,
'&' => static fn ($a, $b) => $a & $b,
'^' => static fn ($a, $b) => $a ^ $b,
'|' => static fn ($a, $b) => $a | $b,
'&&' => static fn ($a, $b) => $a && $b,
'||' => static fn ($a, $b) => $a || $b,
'and' => static fn ($a, $b) => $a and $b,
'xor' => static fn ($a, $b) => $a xor $b,
'or' => static fn ($a, $b) => $a or $b,
];
$separator = '------------------------------';
foreach ($otherValuesNoFrac as $name => $otherVal) {
echo "{$separator} BC vs {$name} {$separator}\n";
foreach ($binaryOps as $op => $fn) {
echo "{$op}: ";
try {
var_dump($fn($num1, $otherVal));
} catch (Throwable $e) {
echo $e::class . ': ' . $e->getMessage() . "\n";
}
}
if ($name === 'BC') {
continue;
}
echo "{$separator} {$name} vs BC {$separator}\n";
foreach ($binaryOps as $op => $fn) {
echo "{$op}: ";
try {
var_dump($fn($otherVal, $num1));
} catch (Throwable $e) {
echo $e::class . ': ' . $e->getMessage() . "\n";
}
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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).
Version System time (s) User time (s) Memory (MiB) 8.4.12 0.014 0.009 22.24 8.4.11 0.012 0.010 18.95 8.4.10 0.014 0.012 17.96 8.4.9 0.015 0.008 17.99 8.4.8 0.005 0.006 17.96 8.4.7 0.019 0.009 17.99 8.4.6 0.014 0.011 18.07 8.4.5 0.017 0.004 18.84 8.4.4 0.016 0.006 17.87 8.4.3 0.023 0.006 19.40 8.4.2 0.010 0.013 19.38 8.3.25 0.007 0.008 18.92 8.3.24 0.015 0.005 16.55 8.3.23 0.013 0.006 16.76 8.3.22 0.010 0.008 17.20 8.3.21 0.011 0.008 16.57 8.3.20 0.010 0.008 16.51 8.3.19 0.004 0.004 17.17 8.3.18 0.010 0.009 18.74 8.3.17 0.009 0.009 17.25 8.3.16 0.013 0.006 18.33 8.3.15 0.009 0.006 18.41 8.3.5 0.008 0.000 18.48 8.2.29 0.011 0.009 20.29 8.2.28 0.010 0.008 18.59 8.2.27 0.008 0.000 18.62 8.1.32 0.012 0.008 16.41
preferences:dark mode live preview ace vim emacs key bindings
28.68 ms | 403 KiB | 5 Q