Project

General

Profile

Actions

Bug #13426

closed

Improve performance of implicit type conversion using #to_r

Added by watson1978 (Shizuo Fujita) about 7 years ago. Updated about 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:80665]

Description

This patch will improve performance in implicit type conversion using #to_r
At least, Integer#quo will be faster around 40%.
And, this will improve some Time methods which calling quov() internally.

Before

                   user     system      total        real
Integer#quo    2.030000   0.010000   2.040000 (  2.031988)
Time#subsec    2.410000   0.000000   2.410000 (  2.412172)

After

                  user     system      total        real
Integer#quo   1.460000   0.000000   1.460000 (  1.463345)
Time#subsec   2.050000   0.010000   2.060000 (  2.056003)

Test code

require 'benchmark'

Benchmark.bmbm do |x|
  x.report "Integer#quo" do
    5000000.times do
      42.quo(3)
    end
  end

  x.report "Time#subsec" do
    t = Time.now
    4000000.times do
      t.subsec
    end
  end

end

Patch

https://github.com/ruby/ruby/pull/1582

Actions #1

Updated by mrkn (Kenta Murata) about 7 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r58347.


Improve performance of type conversion using to_r

  • object.c: Add to_r in conv_method_tbl.

  • defs/id.def: add to_r.

  • benchmark/bm_int_quo.rb: added.

  • benchmark/bm_time_subsec.rb: added.

[Bug #13426]
[ruby-core:80665]
[Fix GH-1582]

Actions

Also available in: Atom PDF

Like0
Like0