role checker

Benchmark created on


Setup

const userRoles = [13, 53, 3]; 

const GdAdminAndSalesRoles = {
  ROLE_ADMIN: 3,
  ROLE_CONTENT_ADMIN: 10,
  ROLE_DATA_ANALYST: 13,
  ROLE_ENGINEER: 20,
  ROLE_ENGINEER_ADMIN: 21,
  ROLE_SALES: 36,
  ROLE_SALES_INDEED: 52,
  ROLE_SENIOR_ADMIN: 39,
  ROLE_ACCOUNT_MANAGER: 1,
  ROLE_ACCOUNT_MANAGER_INDEED: 53,
};

const GdAdminAndSalesRolesArray = Object.values(GdAdminAndSalesRoles)

Test runner

Ready to run.

Testing in
TestOps/sec
Casting to array each time
userRoles.some((role) => Object.values(GdAdminAndSalesRoles).includes(role))
ready
Using cached array
userRoles.some((role) => GdAdminAndSalesRolesArray.includes(role))
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.