Created
May 26, 2011 14:51
-
-
Save nicolaracco/993301 to your computer and use it in GitHub Desktop.
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
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