[ruby-dev:50034] [Ruby trunk Bug#13354] Improve Time#<=> performance
From:
watson1978@...
Date:
2017-03-22 15:55:51 UTC
List:
ruby-dev #50034
Issue #13354 has been reported by watson1978 (Shizuo Fujita).
----------------------------------------
Bug #13354: Improve Time#<=> performance
https://bugs.ruby-lang.org/issues/13354
* Author: watson1978 (Shizuo Fujita)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Time#<=> will be faster around 60%.
If internal values would have Fixnum,
optimized function improves performance.
(https://github.com/ruby/ruby/blob/9b69e9fafc329aaa540d5adeb55124f020abfe3c/time.c#L57-L67)
### Before
~~~
user system total real
1.410000 0.000000 1.410000 ( 1.407848)
~~~
### After
~~~
user system total real
0.880000 0.000000 0.880000 ( 0.886662)
~~~
### Test code
~~~
require 'benchmark'
Benchmark.bmbm do |x|
x.report do
t1 = Time.now
t2 = Time.now
10000000.times do
t1 <=> t2
end
end
end
~~~
### Patch
The patch is in https://github.com/ruby/ruby/pull/1546
--
https://bugs.ruby-lang.org/