PDA

View Full Version : fastest Date.parseDate option



andynuss
8 Apr 2010, 6:54 AM
Hi,

I'm just getting started with formatting dates generated in my server, and want to know what is the friendliest String format to send from the server in terms of getting the best performance for parsing the Date with Date.parseDate.

E.g. do I send as seconds since epoch and use:



Date.parseDate(myepochdate, 'U')


or is there a faster way for the javascript code to ingest a Date. If so what is the format of the date string to send from the server, and where do I find the docs?

Andy

evant
8 Apr 2010, 6:57 AM
The fastest is to send it back an actual date object... That way you don't need to parse it ;)

Animal
8 Apr 2010, 7:00 AM
As long as you aren't using native JSON (which only parses literal data), then that's correct, embed "new Date(<milliseconds>)" in your JSON.

andynuss
8 Apr 2010, 10:48 AM
I don't quite understand. I was returning the seconds since epoch as a number field in the json from the server and then using Date.parseDate(json.mydate, 'U') in the grid data store reader in the javascript code. Are you recommended only that I change the json number field to millis and use the new Date() constructor instead of parseDate() in the data store reader?

Animal
8 Apr 2010, 2:33 PM
That's what the 'U' parsing function does. TBH, it won't make a noticeable difference whatever you do.

Currently the performance sensitive area of Ajax apps is the DOM.

We could make Javascript run 90% faster, and our apps would only go 10% faster because of the current generatio of browsers slow DOM performance. (I can't remember the figures, this was from a Crockford talk, and I think he was just picking numbers to make a point. It's a valid point though)