Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0
Firefox 108
Mac OS X 10.15
Desktop
2 years ago
Test name Executions per second
// array .includes 12679112.0 Ops/sec
// set .has 570935.2 Ops/sec
// array .some(!include) 9837363.0 Ops/sec
// set .some(!has) 616316.4 Ops/sec
Script Preparation code:
x
 
var scopes = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/calendar.settings.readonly https://www.googleapis.com/auth/calendar openid https://www.googleapis.com/auth/calendar.events".split(' ');
var requiredScopes = [
  'yasss',
  'https://www.googleapis.com/auth/calendar',
  'https://www.googleapis.com/auth/calendar.events',
  'https://www.googleapis.com/auth/calendar.settings.readonly',
];
Tests:
  • // array .includes

     
    let scopesOk = true;
    for (let i = 0, length = requiredScopes.length; i < length; ++i) {
      if (!scopes.includes(requiredScopes[i])) {
        // console.log("early break");
        scopesOk = false;
        break;
      }
      // console.log(i)
    }
  • // set .has

     
    let scopesOk = true;
    const scopeSet = new Set(scopes);
    for (let i = 0, length = requiredScopes.length; i < length; ++i) {
      if (!scopeSet.has(requiredScopes[i])) {
        // console.log("early break");
        scopesOk = false;
        break;
      }
    }
  • // array .some(!include)

     
    let scopesOk = requiredScopes.some(scope => !scopes.includes(scope))
  • // set .some(!has)

     
    const scopeSet2 = new Set(scopes);
    let scopesOk = requiredScopes.some(scope => !scopeSet2.has(scope))