Created
November 23, 2012 01:28
-
-
Save dchest/4133602 to your computer and use it in GitHub Desktop.
Comma is faster than semicolon in Safari / JavaScriptCore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ** Update: | |
// ** THIS ONLY AFFECTS CODE PASTED INTO WEB INSPECTOR CONSOLE | |
// ** ACTUAL LOADED CODE ON WEB PAGE RUNS ALMOST THE SAME WITH COMMAS OR SEMICOLONS. | |
// ** | |
// Safari Version 6.0.2 (8536.26.17) | |
// Output: | |
// | |
// comma: 193 ms | |
// semicolon: 575 ms | |
(function() { | |
var t1=(new Date()).getTime(); | |
var a=1, b=2, c=3, d=4; | |
for (var i = 0; i < 1000000; i++) { | |
a^=b, | |
b^=a, | |
b+=c, | |
d+=a, | |
a^=c, | |
d^=a, | |
c+=d | |
} | |
console.log('comma: '+((new Date()).getTime()-t1)+' ms'); | |
t1=(new Date()).getTime(); | |
a=1; b=2; c=3; d=4; | |
for (var i = 0; i < 1000000; i++) { | |
a^=b; | |
b^=a; | |
b+=c; | |
d+=a; | |
a^=c; | |
d^=a; | |
c+=d; | |
} | |
console.log('semicolon: '+((new Date()).getTime()-t1)+' ms'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment