Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var fakeSwitch = {
test0: function() {},
test1: function() {},
test2: function() {},
test3: function() {},
test4: function() {}
}
function testFakeSwitch(item) {
fakeSwitch[item]()
}
function testRealSwitch(item) {
switch(item) {
case 'test0':
break
case 'test1':
break
case 'test2':
break
case 'test3':
break
case 'test4':
break
}
}
// Test Real Switch
setTimeout(function() {
var timer = performance.now()
for(var i = 0; i < 1000000; i++) {
testRealSwitch('test4')
}
console.log('real: ' + (performance.now() - timer))
}, 0)
// Test Fake Switch
setTimeout(function() {
var timer = performance.now()
for(var i = 0; i < 1000000; i++) {
testFakeSwitch('test4')
}
console.log('fake: ' + (performance.now() - timer))
}, 500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment