News for hackers. Stuff that matters.
Re:Ruby's Date/DateTime classes rewritten in C.. 20-200x per... by j-g-faustus on Monday August 23, 2010 @10:36AM (#1626863)
I got something like a 10x performance improvement (for custom code parsing stock quotes from CSV) merely by rewriting Ruby's Date class in Ruby. The default Ruby Date implementation is awfully slow.
Re:Ruby's Date/DateTime classes rewritten in C.. 20-200x per... by _pius on Monday August 23, 2010 @12:12PM (#1627145)
Have you submitted that as a patch?
Re:Ruby's Date/DateTime classes rewritten in C.. 20-200x per... by j-g-faustus on Monday August 23, 2010 @12:48PM (#1627241)
No, I implemented only the subset of the Date API I needed for the application. A fully-fledged Ruby Date would be a larger project.

+1 for duck typing, a custom non-Date object can look like a date for operations that only use a subset of the methods.

Re:Ruby's Date/DateTime classes rewritten in C.. 20-200x per... by jrockway on Monday August 23, 2010 @04:10PM (#1627882)
How many other people have half-started implementations of the same thing? That's why it's important to publish your code somewhere, even if it's "not good enough". Someone else can make it good enough.
Re:Ruby's Date/DateTime classes rewritten in C.. 20-200x per... by weaksauce on Monday August 23, 2010 @12:12PM (#1627146)
Any idea on what edge cases you might be missing out on that would make your version X times faster? Or, why their version is so slow?
Re:Ruby's Date/DateTime classes rewritten in C.. 20-200x per... by psadauskas on Monday August 23, 2010 @01:04PM (#1627282)
Date.parse is really incredibly slow, because it tries all the format parsers until it get one that works. If the format you're trying to parse is low in that list, its going to be very slow.

If you know your format (iso8601, etc), you're better off just using the right parser instead of Date.parse.

Also the internal representation uses Rational, which can be pretty slow itself.

Date.parse: http://github.com/ruby/ruby/blob/trunk/lib/date/format.rb#L1...

edit: correction to how parse works.

Re:Ruby's Date/DateTime classes rewritten in C.. 20-200x per... by j-g-faustus on Monday August 23, 2010 @12:43PM (#1627225)
I implemented just the subset of the Date API I needed for the application, so it didn't do conversions to other calendar formats (Julian/ordinal/commercial etc.).

I don't know why their version is so slow, I can only imagine that the conversion to Astronomical Julian Day (the Ruby Date internal representation) is expensive, inefficient or both.

I used year/month/day ints as internal representation, which was fast for my use cases (parse date string, format date string, compare two dates).