public
Last active

Comma is faster than semicolon in Safari / JavaScriptCore

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// ** 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');
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.