Javascript timestamp
I look for the best performance in my javascript code. And sometimes short sentences looks better and works slower. For example, we have several ways to get timestamp in JavaScript.
And looks like
new Date().getTime()
is almost twice faster then
+new Date()
And the last one is even slower then jQuery "now" function
$.now()
Here are the test on JsPerf
If you works with dates a lot then it makes sense to think of the fastest way.
Written by Aleksandr Denisenko
Related protips
2 Responses
Date.now() is faster when available. Check the edit of the JsPerf. http://jsperf.com/test-the-speed-of-now/3 :)
Date.now() is the best. Thanks for the good note!
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside