1.8.7 Patch reduces time cost of Rational operations by 50%.
This changes adds a specialize Fixnum#gcd and a tuned rational.rb.
Reduced overall time on Rational operations by > 50%.
user system total real
testit 22.380000 2.140000 24.520000 ( 24.559388)
testit ksrational 17.870000 1.830000 19.700000 ( 19.687221)
testit ks_rational + Fixnum#gcd 10.660000 0.000000 10.660000 ( 10.665765)
The patch will perform better with Fixnum#gcd on numeric.c but still is faster with only the rational.rb changes.
I have a version for 1.8.6 if someone wants it.
ext/rational/rational.c: Added to provide a fast implementation
of Fixnum#gcd (and maybe some others in the future) in C. The
base code was submitted by Kurt Stephens. [Feature #2561]
ext/rational/lib/rational.rb: Moved from lib/rational.rb. Make
overall code optimization; submitted by Kurt Stephens.
Add tests for Rational, ported from trunk.
test/rational/testfixnumgcd.rb: Add a test for Integer#gcd.
Case values are only provided for i386 and amd64 at the moment;
submitted by Kurt Stephens. [Feature #2561]
#4 Updated by Kurt Stephens about 4 years ago
Fixed Fixnum#gcd to FIXNUM_MIN on 64-bit longs.
gcd_test.rb should pass on 64-bit builds.
#5 Updated by Akinori MUSHA about 4 years ago
Patches look fine to me. I'll handle this as soon as I can take the time, hopefully within a couple weeks.
I think it's better to have the C part as extension rather than putting Fixnum#gcd solely in the core,
so I'll make some layout changes to bring this in in the best shape for future maintainability.