From: watson1978@... Date: 2017-03-23T11:08:29+00:00 Subject: [ruby-dev:50036] [Ruby trunk Bug#13357] Improve Time#+ & Time#- performance Issue #13357 has been reported by watson1978 (Shizuo Fujita). ---------------------------------------- Bug #13357: Improve Time#+ & Time#- performance https://bugs.ruby-lang.org/issues/13357 * Author: watson1978 (Shizuo Fujita) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- 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 -- https://bugs.ruby-lang.org/