4 ms·
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?
by weaksauce 16y ago
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?
- j-g-faustus 16y agoI 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).
- psadauskas 16y agoDate.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#L1028 http://github.com/ruby/ruby/blob/trunk/lib/date/format.rb#L1... edit: correction to how parse works.