Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- tries = 100000,
- cnt,
- name,
- names = ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
- nLen = names.length,
- switchTime,
- callTime;
- function getName()
- {
- for (var j, x, i = nLen; i; j = Math.floor(Math.random() * i), x = names[--i], names[i] = names[j], names[j] = x);
- return names[0];
- }
- function callByName(name)
- {
- // ...
- }
- switchTime = (new Date()).getTime();
- cnt = tries;
- while (cnt--) {
- name = getName();
- switch (name) {
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- // for_all_non_default()
- if (name == 'a') {
- // for_A()
- } else if (name == 'b') {
- // for_B()
- } else if (name == 'c') {
- // for_C()
- } else if (name == 'd') {
- // for_D()
- } else if (name == 'e') {
- // for_E()
- } else if (name == 'f') {
- // for_F()
- }
- break;
- default:
- // for_default()
- }
- }
- switchTime = (new Date()).getTime() - switchTime;
- callTime = (new Date()).getTime();
- cnt = tries;
- while (cnt--) {
- name = getName();
- if (names.indexOf(name) != -1) {
- // for_all_non_default()
- callByName(name);
- } else {
- // for_default()
- }
- }
- callTime = (new Date()).getTime() - callTime;
- console.log(switchTime, callTime);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement