Skip to content

Instantly share code, notes, and snippets.

@nicolaracco
Created May 26, 2011 14:51
Show Gist options
  • Save nicolaracco/993301 to your computer and use it in GitHub Desktop.
Save nicolaracco/993301 to your computer and use it in GitHub Desktop.
function testWithoutParentheses() {
var start = new Date();
var end;
var a = 0;
for (var i = 0; i < 1000000000; i++)
if (i % 2 == 0)
a++;
end = new Date();
return end-start;
}
function testWithParentheses() {
var start = new Date();
var end;
var a = 0;
for (var i = 0; i < 1000000000; i++) {
if (i % 2 == 0) {
a++;
}
}
end = new Date();
return end-start;
}
function benchmark() {
var wins1 = 0;
var wins2 = 0;
var without, withi, diff;
for (var i = 0; i < 10; i++) {
without = testWithoutParentheses();
withi = testWithParentheses();
diff = without - withi;
console.log((i + 1) + " iteration: { with: " + withi + "; without: " + without + "; diff: " + diff + " }");
if (diff > 0)
wins1++;
else
wins2++;
}
console.log("without: " + wins1 + ", with: " + wins2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment