I need to convert tons of date strings into absolute times. This generates an example data set of 10,000 strings:
dateStrings=DateString[#,{"Year","-","Month","-","Day"," ","Hour",":","Minute",":","Second"}]&/@
Range[3576302100-10000,3576302100];
I think the simplest way is
AbsoluteTime /@ dateStrings
and this gives exactly the result I want. But on lists of hundreds of thousands of dates, it is quite slow. On the example data set, it takes about 5 s. I can speed it up it a bit by telling AbsoluteTime
what date format to expect:
AbsoluteTime[{#, {"Year", "-", "Month", "-", "Day", " ",
"Hour", ":", "Minute", ":", "Second"}}
] & /@ dateStrings;
And this takes about 3.8 s.
How can the performance be improved further?
f[x_Integer] := Evaluate[DateString[ x, {"Year", "-", "Month", "-", "Day", " ", "Hour", ":", "Minute", ":", "Second"}]];
andf /@ Range[3576302100 - 10000, 3576302100]
? For me this is about 4 times faster. But there is a hint thatx
can not be interpreted as a date or time input. Perhaps there is a way to definef
in a way that this warning does not occur. $\endgroup$