Trying to create a date from a string in Racket - find-seconds VERY slow, week-day year-day required?

Viewed 1267

I'm trying to parse dates from a large csv file in Racket.

The most straightforward way to do this would be to create a new date struct. But it requires the week-day and year-day parameters. Of course I don't have these, and this seems like a real weakness of the date module that I don't understand.

So, as an alternative, I decided to use find-seconds to convert the raw date vals into seconds and then pass that to seconds->date. This works, but is brutally slow.

(time
 (let loop ([n 10000])
   (apply find-seconds '(0 0 12 1 1 2012)) ; this takes 3 seconds for 10000
   ;(date 0 0 12 1 1 2012 0 0 #f 0) ; this is instant
   (if (zero? n)
       'done
       (loop (sub1 n)))))

find-seconds takes 3 seconds to do 10000 values, and I have several million. Creating the date struct is of course instant, but I don't have the week-day, year-day values.

My questions are:

1.) Why is week-day/year-day required for creating date structs?

2.) Is find-seconds supposed to be this slow (ie, bug)? Or am I doing something wrong?

3.) Are there any alternatives to parse dates in a fast manner. I know srfi/19 has a string->date function, but I'd then have to change everything to use that module's struct instead of racket's built-in one. And it may suffer the same performance hit of find-seconds, I'm not sure.

2 Answers
Related