Skip to content

Instantly share code, notes, and snippets.

@dchest
Created November 23, 2012 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dchest/4133602 to your computer and use it in GitHub Desktop.
Save dchest/4133602 to your computer and use it in GitHub Desktop.
Comma is faster than semicolon in Safari / JavaScriptCore
// ** 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