refactor: use `stdlib_base_fmod` instead of built-in in `math/base/special/gcd`
Description
What is the purpose of this pull request?
This pull request:
- replaces the use of built-in
fmodby ourstdlib_base_fmodinmath/base/special/gcd.
Related Issues
Does this pull request have any related issues?
None.
Questions
Any questions for reviewers of this pull request?
No.
Other
Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.
I've changed the js implementation as well, to use our fmod instead of its % operator, so that both the implementations are close enough.
Checklist
Please ensure the following tasks are completed before submitting this pull request.
- [x] Read, understood, and followed the contributing guidelines.
@stdlib-js/reviewers
As discussed, I generated benchmark results before and after making the changes proposed in this PR.
Before:
benchmark.js:
TAP version 13
# @stdlib/math/base/special/gcd
---
iterations: 10000000
elapsed: 0.202160416
rate: 49465667.89811117
...
ok 1 benchmark finished
# @stdlib/math/base/special/gcd
---
iterations: 10000000
elapsed: 0.200456208
rate: 49886207.565095715
...
ok 2 benchmark finished
# @stdlib/math/base/special/gcd
---
iterations: 10000000
elapsed: 0.200792958
rate: 49802543.37405598
...
ok 3 benchmark finished
#
1..3
# total 3
# pass 3
#
# ok
benchmark.native.js:
TAP version 13
# @stdlib/math/base/special/gcd::native
---
iterations: 10000000
elapsed: 0.446446833
rate: 22399083.74487226
...
ok 1 benchmark finished
# @stdlib/math/base/special/gcd::native
---
iterations: 10000000
elapsed: 0.442721583
rate: 22587559.278762337
...
ok 2 benchmark finished
# @stdlib/math/base/special/gcd::native
---
iterations: 10000000
elapsed: 0.452107708
rate: 22118623.113587793
...
ok 3 benchmark finished
#
1..3
# total 3
# pass 3
#
# ok
After:
benchmark.js:
TAP version 13
# @stdlib/math/base/special/gcd
---
iterations: 10000000
elapsed: 0.205398375
rate: 48685876.89654312
...
ok 1 benchmark finished
# @stdlib/math/base/special/gcd
---
iterations: 10000000
elapsed: 0.202361708
rate: 49416463.711602986
...
ok 2 benchmark finished
# @stdlib/math/base/special/gcd
---
iterations: 10000000
elapsed: 0.207460667
rate: 48201908.075423285
...
ok 3 benchmark finished
#
1..3
# total 3
# pass 3
#
# ok
benchmark.native.js:
TAP version 13
# @stdlib/math/base/special/gcd::native
---
iterations: 10000000
elapsed: 0.435659958
rate: 22953681.687679913
...
ok 1 benchmark finished
# @stdlib/math/base/special/gcd::native
---
iterations: 10000000
elapsed: 0.433399375
rate: 23073406.601013213
...
ok 2 benchmark finished
# @stdlib/math/base/special/gcd::native
---
iterations: 10000000
elapsed: 0.438695959
rate: 22794830.43973058
...
ok 3 benchmark finished
#
1..3
# total 3
# pass 3
#
# ok
Looks like while the addon performance has improved, the performance of javascript became slower. Only changing the C implementation could be a possible way.
@gunjjoshi Yes, I think only using fmod in the C implementation is the path forward here.