-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize result representation for BcMathCalculator (#748)
* Optimize result representation for BcMathCalculator::add and BcMathCalculator::substract
- Loading branch information
Showing
5 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Benchmark\Money\Calculator; | ||
|
||
use Money\Calculator\BcMathCalculator; | ||
|
||
class BcMathCalculatorBench extends CalculatorBench | ||
{ | ||
protected function getCalculator(): string | ||
{ | ||
return BcMathCalculator::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Benchmark\Money\Calculator; | ||
|
||
use Money\Calculator; | ||
use Money\Money; | ||
|
||
abstract class CalculatorBench | ||
{ | ||
/** | ||
* @psalm-return class-string<Calculator> | ||
*/ | ||
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Benchmark\Money\Calculator; | ||
|
||
use Money\Calculator\GmpCalculator; | ||
|
||
class GmpCalculatorBench extends CalculatorBench | ||
{ | ||
protected function getCalculator(): string | ||
{ | ||
return GmpCalculator::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters