Ruby and Date classes
I’d seen this somewhere before, but thought I’d benchmark it to see if it was true. Ruby has 3 classes for doing dates. There is Date, DateTime and Time classes. In languages like C# and PHP, the equivalent DateTime class is the one that is generally utilized to do date/time manipulations. However, in Ruby, DateTime and Time are nearly identical classes, the difference being that DateTime is a convenience class. Benchmarking shows the DateTime class to be 20-25 times slower than the native Time class. After doing a little research, the reason is clear. The Time class is a native class developed in C, the DateTime is a wrapper class written in Ruby. So while I rarely have occasion to do time manipulation in a loop — it would seem that the DateTime class should pretty much always be avoided. In fact, I can’t see why the DateTime class exists. I don’t see what it does that isn’t available in either the Date class or Time class.
–TR
1 Comment to Ruby and Date classes
Leave a comment
Categories
- Access 2006
- ALA Midwinter 2007
- ALA Summer 2007
- Book
- C#
- Code4Lib 2007
- Code4Lib2008
- Conferences
- CONTENTdm
- Cycling
- Digital Libraries
- Dspace
- Education
- Family
- General Computing
- Innovative Interfaces
- Java
- LibraryFind
- MarcEdit
- Microsoft
- NWIUG 2006
- OAI
- OCLC
- Open Library
- OSCON 2006
- Patent Stupidity
- Programming
- rails
- Readex
- Readex 2006
- ruby
- Running
- Simpsons
- Travel
- Uncategorized
- Wii
- Wikipedia
Archive
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
It seems, that Time can only deal with dates starting from 1970, while Date and DateTime, although a lot more complex, can deal with practically any date.
As an example, if you want to calculate the age of someone born in 1969 or before, you may have to use Date or DateTime.