开发者

What is faster in those two JavaScript codes?

开发者 https://www.devze.com 2023-04-13 01:36 出处:网络
I know that PHP performance is affe开发者_Python百科cted by things like these so my question is what is faster.

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

精彩评论

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

关注公众号