Guest User

Untitled

a guest
May 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. var fakeSwitch = {
  2. test0: function() {},
  3. test1: function() {},
  4. test2: function() {},
  5. test3: function() {},
  6. test4: function() {}
  7. }
  8.  
  9. function testFakeSwitch(item) {
  10. fakeSwitch[item]()
  11. }
  12.  
  13. function testRealSwitch(item) {
  14. switch(item) {
  15. case 'test0':
  16. break
  17. case 'test1':
  18. break
  19. case 'test2':
  20. break
  21. case 'test3':
  22. break
  23. case 'test4':
  24. break
  25. }
  26. }
  27.  
  28. // Test Real Switch
  29. setTimeout(function() {
  30. var timer = performance.now()
  31. for(var i = 0; i < 1000000; i++) {
  32. testRealSwitch('test4')
  33. }
  34. console.log('real: ' + (performance.now() - timer))
  35. }, 0)
  36.  
  37. // Test Fake Switch
  38. setTimeout(function() {
  39. var timer = performance.now()
  40. for(var i = 0; i < 1000000; i++) {
  41. testFakeSwitch('test4')
  42. }
  43. console.log('fake: ' + (performance.now() - timer))
  44. }, 500)
Add Comment
Please, Sign In to add comment