开发者

What is faster in those two JavaScript codes?

I know that PHP performance is affe开发者_Python百科cted by things like these so my question is what is faster.

This one

Math.random()*99999

or this one

new Date().getTime()

I intend to use the result to append to a URL for cache-busting purposes.


A test case at http://jsperf.com/datevsrand shows that Math.random() is significantly faster, but even then on my computer you can generate 6,5 million timestamps per second.

So, again, there's no practical difference. If there's a performance bottleneck, this won't be it.

Also note that in contrast to a server-side language like PHP it doesn't make any difference to the web site's performance even if you had millions of users because the calculation is done on the client's computer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜