Re: Add bcdivmod() to BCMath
Hi Marco, Benjamin,
> As for tuple vs reference, I think the general direction is to move away from references as
> much as possible, and AFAIK references actually make things harder for IDEs and static analysis
> tools, whereas the tuple syntax array{string, string} is well understood at least by PhpStorm, Psalm
> and PHPStan, which can correctly type the function's return value in their stubs.
I see, I agree. This problem seems to be solved by using PHPDoc.
> I'm wondering if an array vs an object allocation makes a difference here, or if the
> amount of bcdivmod()
execution dwarfs this sort of concern?
>
> Thinking:
>
> ```php
> $result = \bcdivmod('123', '2');
>
> echo $result->quotient; // '61'
> echo $result->remainder; // '1'
> ```
>
> No idea if that's relevant, so I'm throwing it in the room.
BCMath is significantly faster in master, so its cost may have a significant impact.
For reference, here is a speed comparison with 8.3 on my env. The benchmark used is the code from
ext-decimal, which is often introduced in the context of "BCMath is slow”. The unit of all
measurement results is "seconds".
https://php-decimal.github.io/#performance
8.3
- add int: 3.7771
- add string: 3.0387
- sub int: 3.491
- sub string: 3.0248
- mul int: 5.3318
- mul string: 5.7315
- div int: 10.6659
- div string: 25.762
Master
- add int: 1.72
- add string: 1.4444
- sub int: 1.763
- sub string: 1.4745
- mul int: 2.2038
- mul string: 2.0621
- div int: 2.8515
- div string: 2.9411
Regards,
Saki
Thread (11 messages)