Performance - Date.now() vs Date.getTime()
These things are the same (edit semantically; performance is a little better with .now()
):
var t1 = Date.now();
var t2 = new Date().getTime();
However, the time value from any already-created Date
instance is frozen at the time of its construction (or at whatever time/date it's been set to). That is, if you do this:
var now = new Date();
and then wait a while, a subsequent call to now.getTime()
will tell the time at the point the variable was set.
They are effectively equivalent, but you should use Date.now()
. It's clearer and about twice as fast.
Edit: Source: http://jsperf.com/date-now-vs-new-date
When you do (new Date()).getTime()
you are creating a new Date object. If you do this repeatedly, it will be about 2x slower than Date.now()
The same principle should apply for Array.prototype.slice.call(arguments, 0)
vs [].slice.call(arguments, 0)