enableiot / iotkit-agent

Edge agent to abstract cloud connectivity complexities
BSD 2-Clause "Simplified" License
82 stars 49 forks source link

newTimeStamp function duplicates built-in Date.now #24

Closed rwaldron closed 9 years ago

rwaldron commented 10 years ago

This one is interesting, not only is a duplication of the built-in function Date.now(), it also calls Math.round on a number that's already an integer, ie. the return value of new Date().getTime(). Incidentally, Date.now() is just a faster new Date().getTime().

nitsugahcram commented 10 years ago

Great Feedback, just to add some perftest http://jsperf.com/new-date3e3e421312, I will push for this change

rwaldron commented 10 years ago

Micro benchmarks are an anti-pattern. Especially ones that compare apples vs. oranges. new Date() alone doesn't return the same thing as the other 3 and the valueOf/getTime will short-circuit to the same internal operation (notice they measure almost identically). Date.now() is always going to be faster because it doesn't require the initialization/allocation of a complete Date object, where the others do.

KlaudiaJ commented 9 years ago

Changes were applied and merged to development.