Though I don't see a browser ever doing this often enough to make a noticeable difference in an application, the results I'm getting from the following little test were interesting.
I expected the arithmetic version to be faster than the function call. However it seems the function call is the fastest of the three, where I'm sitting.
That
is interesting. But as always, it's virtually impossible to generalize performance optimizations with JavaScript across implementations. What's faster on one implementation is often slower on another. Even such simple and obvious things as counting backward to zero [for (i = 100; i > 0; --i)] rather than forward to a limit [for (i = 0; i < 100; ++i)], which you would
think would always be faster because of the very optimizable "greater than zero" comparison, can't be relied upon.
But your getTime results
are interesting. On both Chrome and Firefox for Linux, in my tests, getTime is
markedly Faster than the other options (I expect they're inlining the call, and since there's no conditional checks required as with converting to number...), whereas on IE6 and IE8 on Windows, that's the
slowest option. (And Opera for Linux shows a marked preference for the + sign.)
Here's a quick-and-dirty test bed: jsbin dot com/ukaju4
--
T.J. Crowder
tj / crowder software / com