Project

General

Profile

Actions

Feature #4257

closed

switch_hitter - an acceleration of date library

Added by tadf (tadayoshi funaba) over 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
-
[ruby-core:34305]

Description

=begin
switch_hitter'ed already passed nearly all of tests (except some tests
of class name and some confirmations of format of inspect).

  • The constructors may return Date::Light instead of Date.
  • as fast as home_run when it represents simple date of proleptic
    gregorian of the age of the human race.
  • keeps compatibility.
    • can load ruby 1.9.2 dumped marshal.
  • accepts flonum explicitly with limitations.
    • If the given offset is flonum, DateTime assumes its precision is
      at most second.
    • If the given +/- argument is flonum, DateTime assumes its
      precision is at most nanosecond.

I'd like to apply this to trunk in the near future.
I also have a plan of improvement about some format methods.

see also http://redmine.ruby-lang.org/issues/show/4068
=end


Files

switch_hitter.patch2 (83.8 KB) switch_hitter.patch2 tadf (tadayoshi funaba), 01/10/2011 09:52 PM
switch_hitter.patch3 (97.4 KB) switch_hitter.patch3 tadf (tadayoshi funaba), 01/16/2011 09:25 PM
switch_hitter.patch4 (97.4 KB) switch_hitter.patch4 tadf (tadayoshi funaba), 02/13/2011 01:22 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #4068: Replace current standard Date/DateTime library with home_runRejectedtadf (tadayoshi funaba)11/18/2010Actions
Actions #1

Updated by jeremyevans0 (Jeremy Evans) over 13 years ago

=begin
I ran switch_hitter against home_run's test suites. Most of the failures are due to differences between home_run and the standard library. There are a few failures that I think should be addressed in switch_hitter:

  1. Operator methods such as >>, <<, +, and - and methods such as next_day and prev_day should return instances that are the same class of the receiver. This could be complicated as subclasses are generally going to subclass Date and DateTime instead of Date::Light and DateTime::Light. I think it's fair to return a Date::Light for a Date or DateTime::Light for a DateTime, but if the receiver is an instance of a subclass of Date or DateTime, the operator method should return an instance the same subclass.

  2. Class methods such as civil, new, commercial, ordinal, and jd should return instances of the class. Similar to 1), Date.new can return Date or Date::Light, but a subclass of Date should return an instance of that subclass.

  3. Strings returned by Date or DateTime methods should use US-ASCII encoding by default, or the default internal encoding if set.

  4. Date parsing methods such as parse, strptime, httpdate, iso8601, etc. are broken (but the DateTime versions are not).

ruby-head :001 > Date.parse '1/1/2011'
ArgumentError: cannot create
from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:803:in new_l!' from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:803:in new!'
from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:1081:in new_by_frags' from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:1123:in parse'
from (irb):1
from /home/jeremy/.rvm/rubies/ruby-head/bin/irb:16:in `'

Related to 1) is that with switch_hitter's design, subclasses of Date and DateTime are not going to have optimized performance. A user would have to subclass Date::Light or DateTime::Light if they wanted their subclass to have optimized performance. I don't really see a way around this without having some Date objects use internal type T_DATA and other Date objects use internal type T_OBJECT, and having a ruby class whose objects can differ in internal type is probably not a good idea.
=end

Actions #2

Updated by tadf (tadayoshi funaba) over 13 years ago

=begin
i've integrated both.
=end

Actions #3

Updated by jeremyevans0 (Jeremy Evans) about 13 years ago

=begin
Looks good. The only thing I noticed is that DateTime#amjd is broken:

$ ruby -v -r date -e 'DateTime.new.amjd'
ruby 1.9.3dev (2011-01-21 trunk 30620) [x86_64-openbsd4.8]
-e:1:in amjd': undefined method amjd_r' for #<DateTime[R]: -4712-01-01T00:00:00+00:00 (-1/2,0,2299161)> (NoMethodError)
from -e:1:in `'

=end

Actions #4

Updated by tadf (tadayoshi funaba) about 13 years ago

=begin
i'm planning to apply this change within a couple of weeks.
=end

Actions #5

Updated by headius (Charles Nutter) about 13 years ago

=begin
Added http://jira.codehaus.org/browse/JRUBY-5518 to track this. We'll want to implement a Java version of switch_hitter, most likely.
=end

Actions #6

Updated by jeremyevans0 (Jeremy Evans) about 13 years ago

=begin
Looks good, no unexpected failures in home_run's test suite.
=end

Updated by tadf (tadayoshi funaba) about 13 years ago

  • Status changed from Open to Closed

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0