aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/date_time_ext_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2012-07-02 07:05:17 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2012-07-02 07:05:17 +0100
commit822c858a1a5cad49274404dbc10b7f8107b06cc3 (patch)
tree3a4a2e509ba64d04900a874988f04d19e446242b /activesupport/test/core_ext/date_time_ext_test.rb
parent83302a4c1384c18bec7128ec561eb6a8aa674275 (diff)
downloadrails-822c858a1a5cad49274404dbc10b7f8107b06cc3.tar.gz
rails-822c858a1a5cad49274404dbc10b7f8107b06cc3.tar.bz2
rails-822c858a1a5cad49274404dbc10b7f8107b06cc3.zip
Improve performance of DateTime#seconds_since_unix_epoch
Calculate the seconds since the UNIX epoch using the difference in Julian day numbers from the epoch date. By reducing the Rational math to just the offset component this gives a significant improvement. Benchmark: Calculating -------------------------------------------- new 27733 i/100ms current 15031 i/100ms new 27737 i/100ms current 15549 i/100ms -------------------------------------------------------- new 548182.1 (±0.9%) i/s - 2745567 in 5.008943s current 216380.9 (±1.6%) i/s - 1082232 in 5.002781s new 510281.9 (±1.2%) i/s - 2551804 in 5.001525s current 219858.3 (±1.8%) i/s - 1103979 in 5.023039s
Diffstat (limited to 'activesupport/test/core_ext/date_time_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb1
1 files changed, 1 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index 183d58482d..21b7efdc73 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -427,6 +427,7 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
def test_to_i
assert_equal 946684800, DateTime.civil(2000).to_i
+ assert_equal 946684800, DateTime.civil(1999,12,31,19,0,0,Rational(-5,24)).to_i
end
protected