https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-05-21T03:36:37ZRuby Issue Tracking SystemRuby master - Bug #13357: Improve Time#+ & Time#- performancehttps://bugs.ruby-lang.org/issues/13357?journal_id=650042017-05-21T03:36:37Zwatson1978 (Shizuo Fujita)watson1978@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r58829.</p>
<hr>
<p>Improve Time#+ & Time#- performance</p>
<ul>
<li>
<p>time.c (wadd): use internal addv() function to calculate internal value in<br>
Time object. On 64-bit machine, Time object might have Fixnum object<br>
internally by default and addv() can calculate Fixnum objects directly.</p>
</li>
<li>
<p>time.c (wsub): use internal subv() function due the same reason in above.</p>
<p>Time#+ & Time#- will be faster around 15%.</p>
<p><a href="/issues/13357">[ruby-dev:50036]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Improve Time#+ & Time#- performance (Closed)" href="https://bugs.ruby-lang.org/issues/13357">#13357</a>] [Fix GH-1547]</p>
</li>
</ul>
<a name="Before"></a>
<h3 >Before<a href="#Before" class="wiki-anchor">¶</a></h3>
<pre><code> user system total real
</code></pre>
<p>Time#+ 0.820000 0.000000 0.820000 ( 0.818081)<br>
Time#- 0.810000 0.000000 0.810000 ( 0.813835)</p>
<a name="After"></a>
<h3 >After<a href="#After" class="wiki-anchor">¶</a></h3>
<pre><code> user system total real
</code></pre>
<p>Time#+ 0.710000 0.000000 0.710000 ( 0.710241)<br>
Time#- 0.710000 0.010000 0.720000 ( 0.714151)</p>
<a name="Test-code"></a>
<h3 >Test code<a href="#Test-code" class="wiki-anchor">¶</a></h3>
<p>require 'benchmark'</p>
<p>Benchmark.bmbm do |x|</p>
<p>x.report "Time#+" do<br>
t = Time.now<br>
2000000.times do<br>
t + 1<br>
end<br>
end</p>
<p>x.report "Time#-" do<br>
t = Time.now<br>
2000000.times do<br>
t - 1<br>
end<br>
end</p>
<p>end</p>