Created
May 19, 2018 03:02
-
-
Save sean-codes/b4377661e458efc28a4d5b05d1fe2200 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
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