3 ms·
They're the same, +new Date doing an implicit cast to number. I prefer getTime as well for its clarity.
by russ 16y ago
They're the same, +new Date doing an implicit cast to number. I prefer getTime as well for its clarity.
- loganlinn 16y agoAnd another form is: var I = Number(new Date);
- shazow 16y agoI benchmarked all the variations on Chrome, var foo = +new Date() was the fastest—not by a huge amount than the rest, but I remember there was one approach that was especially slow. I did this while optimizing performance of a fast-paced game in Javascript (LineRage). Profiling showed that getting timestamps was responsible for significant portion of the processing time. I also ended up switching to a global clock approach. Unfortunately I no longer have the original benchmark code/results. Would be happy to have someone replicate it.