Patches: Browse | Submit New | Admin

[#19034] [PATCH] Fixnum#gcd(Fixnum) improves performance of Date, Rational.

Date:
2008-03-22 22:51
Priority:
2
Submitted By:
Kurt Stephens (kstephens)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
[PATCH] Fixnum#gcd(Fixnum) improves performance of Date, Rational.

Detailed description
        * numeric.c (gcd): Added Fixnum#gcd(Fixnum) support in C.
          Date uses Rational heavily, which calls Integer#gcd for every new
          Rational.  The Integer#gcd method is generic to handle Bignums, 
          but performs terribly for Fixnum#gcd(Fixnum), 
          which is probably the most often case.  Improves gcd performance on
          Fixnums by 300% in Ruby 1.9.

Patch for 1.8.6 coming soon.


Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-02-16 06:36
Sender: Akinori MUSHA

The implementation needs to follow such principles as the coerce
architecture. (You have to call rb_num_coerce_relop instead of
calling super, etc.)

I also think that Bignum should be supported within the core
for functional completeness, so I'll try to look into 1.9 and
see if there's stuff there I can bring in.

Maybe I'll add #lcm and #gcdlcm as well when #gcd should be.
Date: 2008-10-30 19:20
Sender: Roger Pack

Looks like the current difference for 1.9 is


=> #<Benchmark::Tms:0x118aa0 @label="",
@real=2.26090502738953, @cstime=0.0, @cutime=0.0, @stime=0.02,
@utime=2.23, @total=2.25>


to

=> #<Benchmark::Tms:0x10e44c @label="",
@real=2.2900869846344, @cstime=0.0, @cutime=0.0, @stime=0.01,
@utime=2.25, @total=2.26>

so at least the current one isn't awful, though this patch is
still slightly faster.
Date: 2008-06-10 02:42
Sender: Roger Pack

+1 for wishing this were committed.
Date: 2008-03-23 00:22
Sender: Kurt Stephens

Ruby 1.8.6 patch improves performance by %1000.

Attached Files:

Name Description Download
ruby-1.8.6-fixnum-gcd-patch.diff Patch for 1.8.6 SVN. Download
ruby-fixnum-gcd-test.rb Performance test for Fixnum#gcd. Download
ruby-1.9-fixnum-gcd-patch.diff Patch for 1.9 SVN. Download

Changes:

Field Old Value Date By
category_idMath2009-02-16 06:36knu
artifact_group_id1.9.x2009-02-16 06:36knu
priority32009-02-16 06:36knu
assigned_toknu2009-02-16 06:36knu
File Added3499: ruby-1.9-fixnum-gcd-patch.diff2008-03-23 00:24kstephens
File Added3498: ruby-fixnum-gcd-test.rb2008-03-23 00:23kstephens
File Added3497: ruby-1.8.6-fixnum-gcd-patch.diff2008-03-23 00:22kstephens