Skip to content

Instantly share code, notes, and snippets.

@sean-codes
Created May 19, 2018 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean-codes/b4377661e458efc28a4d5b05d1fe2200 to your computer and use it in GitHub Desktop.
Save sean-codes/b4377661e458efc28a4d5b05d1fe2200 to your computer and use it in GitHub Desktop.
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