Project

General

Profile

Bug #13418

Improve Time#to_i performance

Added by watson1978 (Shizuo Fujita) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:80636]

Description

Time#to_i will be faster around 80%.

Before

       user     system      total        real
   2.840000   0.000000   2.840000 (  2.847238)

After

       user     system      total        real
   1.600000   0.000000   1.600000 (  1.598911)

Test code

require 'benchmark'

Benchmark.bmbm do |x|
  x.report do
    t = Time.now
    20000000.times do
      t.to_i
    end
  end

end

Patch

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

#1

Updated by Anonymous over 3 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r58308.


time.c: Improve Time#to_i performance

Time#to_i will be faster around 80% (on 64-bit platforms).

  • Before
    user system total real
    2.840000 0.000000 2.840000 ( 2.847238)

  • After
    user system total real
    1.600000 0.000000 1.600000 ( 1.598911)

  • Test code
    require 'benchmark'

Benchmark.bmbm do |x|
x.report do
t = Time.now
20000000.times do
t.to_i
end
end
end

  • time.c (_div): new function avoid rb_funcall (div): replace with new _div function [ruby-core:80636] [Bug #13418] Thanks to Watson watson1978@gmail.com for the patch.

From: Watson watson1978@gmail.com

Also available in: Atom PDF