While looking at this awesome list of browser support for EcmaScript 5 features. I decided to time the difference between using Date.now(), a static method to access the current timestamp, and new Date().getTime(), the previous way to get a current timestamp in JavasScript.
The results are this: As expected, the static method wins!
The testing code can be found here:
http://jsbin.com/eheyi3/2 (I have no idea how long this will stay up):
Or here:
http://jamund.com/tests/date.html
Here are the results running in Chrome 9:
Testing Date.now() 10000000 times
0.908s
Testing new Date().getTime() 10000000 times
1.241s
Here are the results running in FireFox 3.6:
Testing Date.now() 10000000 times
7.144s
Testing new Date().getTime() 10000000 times
12.016s
Here are the reuslts running in FireFox 4:
Testing Date.now() 10000000 times
1.73s
Testing new Date().getTime() 10000000 times
3.677s
Here are the results running in Safari 5:
Testing 'Date.now()' 10,000,000 times
0.74s
Testing 'new Date().getTime()' 10,000,000 times
2.817s
No comments:
Post a Comment