Project

General

Profile

Actions

Feature #2561

closed

1.8.7 Patch reduces time cost of Rational operations by 50%.

Added by kstephens (Kurt Stephens) almost 15 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
-
[ruby-core:27437]

Description

=begin
This changes adds a specialize Fixnum#gcd and a tuned rational.rb.
Reduced overall time on Rational operations by > 50%.

                                               user     system      total        real
 test_it                                  22.380000   2.140000  24.520000 ( 24.559388)
 test_it ks_rational                      17.870000   1.830000  19.700000 ( 19.687221)
 test_it 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.
=end


Files

rational_performance.rb (1.85 KB) rational_performance.rb kstephens (Kurt Stephens), 01/06/2010 10:58 AM
ruby-1.8.7-rational.patch (9.1 KB) ruby-1.8.7-rational.patch kstephens (Kurt Stephens), 01/06/2010 10:58 AM
rational_performance.rb (2.29 KB) rational_performance.rb kstephens (Kurt Stephens), 01/07/2010 03:43 AM
ruby-1.8.7-rational.patch (9.39 KB) ruby-1.8.7-rational.patch kstephens (Kurt Stephens), 01/07/2010 03:43 AM
ruby-1.8.7-rational.patch (10.7 KB) ruby-1.8.7-rational.patch Fixed Fixnum#gcd for FIXNUM_MIN. kstephens (Kurt Stephens), 01/12/2010 01:18 AM
gcd_test.rb (21.6 KB) gcd_test.rb kstephens (Kurt Stephens), 01/12/2010 01:18 AM
gcd_test.rb (44.6 KB) gcd_test.rb 64-bit test cases. kstephens (Kurt Stephens), 01/22/2010 05:58 AM
ruby-1.8.7-fixnum_gcd.patch (1.28 KB) ruby-1.8.7-fixnum_gcd.patch numeric.c patch. kstephens (Kurt Stephens), 01/22/2010 05:58 AM

Related issues 1 (0 open1 closed)

Has duplicate Ruby 1.8 - Backport #838: faster gcd for 187Closedknu (Akinori MUSHA)12/08/2008Actions
Actions #1

Updated by naruse (Yui NARUSE) almost 15 years ago

  • Status changed from Open to Assigned
  • Assignee set to knu (Akinori MUSHA)

=begin
Discuss in Ruby 1.8 first,
=end

Updated by kstephens (Kurt Stephens) almost 15 years ago

=begin
New version:

Avoid additional method calls to Float(), call #to_f directly. Avoid Rational() when its clear that denominator will never be 1.

=end

Actions #5

Updated by knu (Akinori MUSHA) almost 15 years ago

=begin
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.

=end

Actions #6

Updated by knu (Akinori MUSHA) almost 15 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r26581.
Kurt , thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0