Created
July 6, 2010 17:47
-
-
Save miketaylr/465681 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 benchmark(method, times, name){ | |
//See http://gist.github.com/227048 | |
var startTime = (new Date()).getTime(), endTime; | |
while(times--){ | |
method(); | |
} | |
endTime = (new Date()).getTime(); | |
console.log(name, endTime - startTime); | |
} | |
var x = 1, y = 0; | |
benchmark(function(){ | |
y = (x === 0 ? x : x === 1); | |
}, 100000, "Ternary Operator"); | |
x = 1; | |
y = 0; | |
benchmark(function(){ | |
switch(x){ | |
case 0: y = x; break; | |
case 1: y = x; break; | |
default:y = x; break; | |
} | |
}, 100000, "switch Statement"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://miketaylr.com/post/e2d3e153.png