diff --git a/benchmark/Calculator/BcMathCalculatorBench.php b/benchmark/Calculator/BcMathCalculatorBench.php new file mode 100644 index 00000000..cbb80ded --- /dev/null +++ b/benchmark/Calculator/BcMathCalculatorBench.php @@ -0,0 +1,15 @@ + + */ + abstract protected function getCalculator(): string; + + public function benchCompare(): void + { + $this->getCalculator()::compare('1', '1'); + $this->getCalculator()::compare('1', '5'); + $this->getCalculator()::compare('5', '5'); + $this->getCalculator()::compare('5.5', '1.5'); + $this->getCalculator()::compare('1.5', '5.5'); + } + + public function benchAdd(): void + { + $this->getCalculator()::add('1', '5'); + } + + public function benchSubtract(): void + { + $this->getCalculator()::subtract('1', '5'); + } + + public function benchMultiply(): void + { + $this->getCalculator()::multiply('5', '25'); + $this->getCalculator()::multiply('5', '1.5'); + } + + public function benchDivide(): void + { + $this->getCalculator()::divide('5', '4'); + } + + public function benchCeil(): void + { + $this->getCalculator()::ceil('5.5'); + } + + public function benchFloor(): void + { + $this->getCalculator()::floor('5.5'); + } + + public function benchAbsolute(): void + { + $this->getCalculator()::absolute('5'); + $this->getCalculator()::absolute('-5'); + } + + public function benchRound(): void + { + $this->getCalculator()::round('2.6', Money::ROUND_HALF_EVEN); + } + + public function benchShare(): void + { + $this->getCalculator()::share('10', '2', '4'); + } + + public function benchMod(): void + { + $this->getCalculator()::mod('11', '5'); + } +} diff --git a/benchmark/Calculator/GmpCalculatorBench.php b/benchmark/Calculator/GmpCalculatorBench.php new file mode 100644 index 00000000..a026f28c --- /dev/null +++ b/benchmark/Calculator/GmpCalculatorBench.php @@ -0,0 +1,15 @@ +a, $this->b, $this->a, $this->b); + Money::max($this->a, $this->b, $this->a, $this->b); } public function benchAvg(): void { - Money::min($this->a, $this->b, $this->a, $this->b); + Money::avg($this->a, $this->b, $this->a, $this->b); } public function benchRatioOf(): void diff --git a/phpbench.json b/phpbench.json index 2b307866..a6615b16 100644 --- a/phpbench.json +++ b/phpbench.json @@ -1,4 +1,9 @@ { "runner.bootstrap": "vendor/autoload.php", - "runner.path": "benchmark" + "runner.path": "benchmark", + "runner.php_config": + { + "opcache.enable": 1, + "opcache.enable_cli": 1 + } } diff --git a/src/Calculator/BcMathCalculator.php b/src/Calculator/BcMathCalculator.php index 0640c883..e610f679 100644 --- a/src/Calculator/BcMathCalculator.php +++ b/src/Calculator/BcMathCalculator.php @@ -31,13 +31,13 @@ public static function compare(string $a, string $b): int /** @psalm-pure */ public static function add(string $amount, string $addend): string { - return bcadd($amount, $addend, self::SCALE); + return bcadd($amount, $addend, 0); } /** @psalm-pure */ public static function subtract(string $amount, string $subtrahend): string { - return bcsub($amount, $subtrahend, self::SCALE); + return bcsub($amount, $subtrahend, 0); } /** @psalm-pure */