Project

General

Profile

Bug #13357

Improve Time#+ & Time#- performance

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

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-dev:50036]

Description

Improve Time#+ & Time#- performance

Time#+ & Time#- will be faster around 15%.
If internal values would have Fixnum,
optimized function improves performance.

Before

             user     system      total        real
Time#+   0.820000   0.000000   0.820000 (  0.818081)
Time#-   0.810000   0.000000   0.810000 (  0.813835)

After

             user     system      total        real
Time#+   0.710000   0.000000   0.710000 (  0.710241)
Time#-   0.710000   0.010000   0.720000 (  0.714151)

Test code

require 'benchmark'

Benchmark.bmbm do |x|

  x.report "Time#+" do
    t = Time.now
    2000000.times do
      t + 1
    end
  end

  x.report "Time#-" do
    t = Time.now
    2000000.times do
      t - 1
    end
  end

end

Patch

The patch is in https://github.com/ruby/ruby/pull/1547

Associated revisions

Revision c208d15f
Added by watson1978 (Shizuo Fujita) over 2 years ago

Improve Time#+ & Time#- performance

  • time.c (wadd): use internal addv() function to calculate internal value in
    Time object. On 64-bit machine, Time object might have Fixnum object
    internally by default and addv() can calculate Fixnum objects directly.

  • time.c (wsub): use internal subv() function due the same reason in above.

    Time#+ & Time#- will be faster around 15%.

    [ruby-dev:50036] [Bug #13357] [Fix GH-1547]

Before

         user     system      total        real

Time#+ 0.820000 0.000000 0.820000 ( 0.818081)
Time#- 0.810000 0.000000 0.810000 ( 0.813835)

After

         user     system      total        real

Time#+ 0.710000 0.000000 0.710000 ( 0.710241)
Time#- 0.710000 0.010000 0.720000 ( 0.714151)

Test code

require 'benchmark'

Benchmark.bmbm do |x|

x.report "Time#+" do
t = Time.now
2000000.times do
t + 1
end
end

x.report "Time#-" do
t = Time.now
2000000.times do
t - 1
end
end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58829
Added by watson1978 (Shizuo Fujita) over 2 years ago

Improve Time#+ & Time#- performance

  • time.c (wadd): use internal addv() function to calculate internal value in
    Time object. On 64-bit machine, Time object might have Fixnum object
    internally by default and addv() can calculate Fixnum objects directly.

  • time.c (wsub): use internal subv() function due the same reason in above.

    Time#+ & Time#- will be faster around 15%.

    [ruby-dev:50036] [Bug #13357] [Fix GH-1547]

Before

         user     system      total        real

Time#+ 0.820000 0.000000 0.820000 ( 0.818081)
Time#- 0.810000 0.000000 0.810000 ( 0.813835)

After

         user     system      total        real

Time#+ 0.710000 0.000000 0.710000 ( 0.710241)
Time#- 0.710000 0.010000 0.720000 ( 0.714151)

Test code

require 'benchmark'

Benchmark.bmbm do |x|

x.report "Time#+" do
t = Time.now
2000000.times do
t + 1
end
end

x.report "Time#-" do
t = Time.now
2000000.times do
t - 1
end
end

end

Revision 58829
Added by watson1978 (Shizuo Fujita) over 2 years ago

Improve Time#+ & Time#- performance

  • time.c (wadd): use internal addv() function to calculate internal value in
    Time object. On 64-bit machine, Time object might have Fixnum object
    internally by default and addv() can calculate Fixnum objects directly.

  • time.c (wsub): use internal subv() function due the same reason in above.

    Time#+ & Time#- will be faster around 15%.

    [ruby-dev:50036] [Bug #13357] [Fix GH-1547]

Before

         user     system      total        real

Time#+ 0.820000 0.000000 0.820000 ( 0.818081)
Time#- 0.810000 0.000000 0.810000 ( 0.813835)

After

         user     system      total        real

Time#+ 0.710000 0.000000 0.710000 ( 0.710241)
Time#- 0.710000 0.010000 0.720000 ( 0.714151)

Test code

require 'benchmark'

Benchmark.bmbm do |x|

x.report "Time#+" do
t = Time.now
2000000.times do
t + 1
end
end

x.report "Time#-" do
t = Time.now
2000000.times do
t - 1
end
end

end

Revision 58829
Added by watson1978 (Shizuo Fujita) over 2 years ago

Improve Time#+ & Time#- performance

  • time.c (wadd): use internal addv() function to calculate internal value in
    Time object. On 64-bit machine, Time object might have Fixnum object
    internally by default and addv() can calculate Fixnum objects directly.

  • time.c (wsub): use internal subv() function due the same reason in above.

    Time#+ & Time#- will be faster around 15%.

    [ruby-dev:50036] [Bug #13357] [Fix GH-1547]

Before

         user     system      total        real

Time#+ 0.820000 0.000000 0.820000 ( 0.818081)
Time#- 0.810000 0.000000 0.810000 ( 0.813835)

After

         user     system      total        real

Time#+ 0.710000 0.000000 0.710000 ( 0.710241)
Time#- 0.710000 0.010000 0.720000 ( 0.714151)

Test code

require 'benchmark'

Benchmark.bmbm do |x|

x.report "Time#+" do
t = Time.now
2000000.times do
t + 1
end
end

x.report "Time#-" do
t = Time.now
2000000.times do
t - 1
end
end

end

History

#1

Updated by watson1978 (Shizuo Fujita) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r58829.


Improve Time#+ & Time#- performance

  • time.c (wadd): use internal addv() function to calculate internal value in
    Time object. On 64-bit machine, Time object might have Fixnum object
    internally by default and addv() can calculate Fixnum objects directly.

  • time.c (wsub): use internal subv() function due the same reason in above.

    Time#+ & Time#- will be faster around 15%.

    [ruby-dev:50036] [Bug #13357] [Fix GH-1547]

Before

         user     system      total        real

Time#+ 0.820000 0.000000 0.820000 ( 0.818081)
Time#- 0.810000 0.000000 0.810000 ( 0.813835)

After

         user     system      total        real

Time#+ 0.710000 0.000000 0.710000 ( 0.710241)
Time#- 0.710000 0.010000 0.720000 ( 0.714151)

Test code

require 'benchmark'

Benchmark.bmbm do |x|

x.report "Time#+" do
t = Time.now
2000000.times do
t + 1
end
end

x.report "Time#-" do
t = Time.now
2000000.times do
t - 1
end
end

end

Also available in: Atom PDF