Map vs Loop

Benchmark created on


Setup

const permissions = [
  'p1',
  'p2',
  'p3',
  'p4',
  'p5',
  'p6',
  'p7',
  'p8',
  'p9',
  'p10',
  'p11',
  'p12',
  'p13',
  'p14',
  'p15',
  'p16',
  'p17',
  'p18',
  'p19',
  'p20',
  'p21',
  'p22',
  'p23',
  'p24',
  'p25',
  'p26',
  'p27',
  'p28',
  'p29',
  'p30',
  'p31',
  'p32',
  'p33',
  'p34',
  'p35',
  'p36',
  'p37',
  'p38',
  'p39',
  'p40',
  'p41',
  'p42',
  'p43',
  'p44',
  'p45',
  'p46',
  'p47',
  'p48',
  'p49',
  'p50',
  'p51',
  'p52',
  'p53',
  'p54',
  'p55',
  'p56',
  'p57',
  'p58',
  'p59',
  'p60',
  'p61',
  'p62',
  'p63',
  'p64',
  'p65',
  'p66',
  'p67',
  'p68',
  'p69',
  'p70',
  'p71',
  'p72',
  'p73',
  'p74',
  'p75',
  'p76',
  'p77',
  'p78',
  'p79',
  'p80',
  'p81',
  'p82',
  'p83',
  'p84',
  'p85',
  'p86',
  'p87',
  'p88',
  'p89',
  'p90',
  'p91',
  'p92',
  'p93',
  'p94',
  'p95',
  'p96',
  'p97',
  'p98',
  'p99',
  'p100',
];

const companies = [
  'c1',
  'c2',
  'c3',
  'c4',
  'c5',
  'c6',
  'c7',
  'c8',
  'c9',
  'c10',
  'c11',
  'c12',
  'c13',
  'c14',
  'c15',
  'c16',
  'c17',
  'c18',
  'c19',
  'c20',
  'c21',
  'c22',
  'c23',
  'c24',
  'c25',
  'c26',
  'c27',
  'c28',
  'c29',
  'c30',
  'c31',
  'c32',
  'c33',
  'c34',
  'c35',
  'c36',
  'c37',
  'c38',
  'c39',
  'c40',
  'c41',
  'c42',
  'c43',
  'c44',
  'c45',
  'c46',
  'c47',
  'c48',
  'c49',
  'c50',
  'c51',
  'c52',
  'c53',
  'c54',
  'c55',
  'c56',
  'c57',
  'c58',
  'c59',
  'c60',
  'c61',
  'c62',
  'c63',
  'c64',
  'c65',
  'c66',
  'c67',
  'c68',
  'c69',
  'c70',
  'c71',
  'c72',
  'c73',
  'c74',
  'c75',
  'c76',
  'c77',
  'c78',
  'c79',
  'c80',
  'c81',
  'c82',
  'c83',
  'c84',
  'c85',
  'c86',
  'c87',
  'c88',
  'c89',
  'c90',
  'c91',
  'c92',
  'c93',
  'c94',
  'c95',
  'c96',
  'c97',
  'c98',
  'c99',
  'c100',
];

const targetPermission = 'target_p';
const targetCompany = 'target_c';

const roles = [
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions, companies },
  { permissions: [...permissions, targetPermission], companies: [...companies, targetCompany] },
];

const permissions2 = {
  e1: { a1: true },
  e2: { a2: true },
  e3: { a3: true },
  e4: { a4: true },
  e5: { a5: true },
  e6: { a6: true },
  e7: { a7: true },
  e8: { a8: true },
  e9: { a9: true },
  e10: { a10: true },
  e11: { a11: true },
  e12: { a12: true },
  e13: { a13: true },
  e14: { a14: true },
  e15: { a15: true },
  e16: { a16: true },
  e17: { a17: true },
  e18: { a18: true },
  e19: { a19: true },
  e20: { a20: true },
  e21: { a21: true },
  e22: { a22: true },
  e23: { a23: true },
  e24: { a24: true },
  e25: { a25: true },
  e26: { a26: true },
  e27: { a27: true },
  e28: { a28: true },
  e29: { a29: true },
  e30: { a30: true },
  e31: { a31: true },
  e32: { a32: true },
  e33: { a33: true },
  e34: { a34: true },
  e35: { a35: true },
  e36: { a36: true },
  e37: { a37: true },
  e38: { a38: true },
  e39: { a39: true },
  e40: { a40: true },
  e41: { a41: true },
  e42: { a42: true },
  e43: { a43: true },
  e44: { a44: true },
  e45: { a45: true },
  e46: { a46: true },
  e47: { a47: true },
  e48: { a48: true },
  e49: { a49: true },
  e50: { a50: true },
  e51: { a51: true },
  e52: { a52: true },
  e53: { a53: true },
  e54: { a54: true },
  e55: { a55: true },
  e56: { a56: true },
  e57: { a57: true },
  e58: { a58: true },
  e59: { a59: true },
  e60: { a60: true },
  e61: { a61: true },
  e62: { a62: true },
  e63: { a63: true },
  e64: { a64: true },
  e65: { a65: true },
  e66: { a66: true },
  e67: { a67: true },
  e68: { a68: true },
  e69: { a69: true },
  e70: { a70: true },
  e71: { a71: true },
  e72: { a72: true },
  e73: { a73: true },
  e74: { a74: true },
  e75: { a75: true },
  e76: { a76: true },
  e77: { a77: true },
  e78: { a78: true },
  e79: { a79: true },
  e80: { a80: true },
  e81: { a81: true },
  e82: { a82: true },
  e83: { a83: true },
  e84: { a84: true },
  e85: { a85: true },
  e86: { a86: true },
  e87: { a87: true },
  e88: { a88: true },
  e89: { a89: true },
  e90: { a90: true },
  e91: { a91: true },
  e92: { a92: true },
  e93: { a93: true },
  e94: { a94: true },
  e95: { a95: true },
  e96: { a96: true },
  e97: { a97: true },
  e98: { a98: true },
  e99: { a99: true },
  e100: { a100: true },
};

const roles2 = {
  c1: { permissions },
  c2: { permissions },
  c3: { permissions },
  c4: { permissions },
  c5: { permissions },
  c6: { permissions },
  c7: { permissions },
  c8: { permissions },
  c9: { permissions },
  c10: { permissions },
  c11: { permissions },
  c12: { permissions },
  c13: { permissions },
  c14: { permissions },
  c15: { permissions },
  c16: { permissions },
  c17: { permissions },
  c18: { permissions },
  c19: { permissions },
  c20: { permissions },
  c21: { permissions },
  c22: { permissions },
  c23: { permissions },
  c24: { permissions },
  c25: { permissions },
  c26: { permissions },
  c27: { permissions },
  c28: { permissions },
  c29: { permissions },
  c30: { permissions },
  c31: { permissions },
  c32: { permissions },
  c33: { permissions },
  c34: { permissions },
  c35: { permissions },
  c36: { permissions },
  c37: { permissions },
  c38: { permissions },
  c39: { permissions },
  c40: { permissions },
  c41: { permissions },
  c42: { permissions },
  c43: { permissions },
  c44: { permissions },
  c45: { permissions },
  c46: { permissions },
  c47: { permissions },
  c48: { permissions },
  c49: { permissions },
  c50: { permissions },
  c51: { permissions },
  c52: { permissions },
  c53: { permissions },
  c54: { permissions },
  c55: { permissions },
  c56: { permissions },
  c57: { permissions },
  c58: { permissions },
  c59: { permissions },
  c60: { permissions },
  c61: { permissions },
  c62: { permissions },
  c63: { permissions },
  c64: { permissions },
  c65: { permissions },
  c66: { permissions },
  c67: { permissions },
  c68: { permissions },
  c69: { permissions },
  c70: { permissions },
  c71: { permissions },
  c72: { permissions },
  c73: { permissions },
  c74: { permissions },
  c75: { permissions },
  c76: { permissions },
  c77: { permissions },
  c78: { permissions },
  c79: { permissions },
  c80: { permissions },
  c81: { permissions },
  c82: { permissions },
  c83: { permissions },
  c84: { permissions },
  c85: { permissions },
  c86: { permissions },
  c87: { permissions },
  c88: { permissions },
  c89: { permissions },
  c90: { permissions },
  c91: { permissions },
  c92: { permissions },
  c93: { permissions },
  c94: { permissions },
  c95: { permissions },
  c96: { permissions },
  c97: { permissions },
  c98: { permissions },
  c99: { permissions },
  c100: { permissions: { ...permissions, targetA: { targetB: true } } },
};

function checkPermissionDict() {
  const res = roles2.c100.permissions.targetA.targetB;
  return res;
}

function checkPermissionLoop() {
  const role = roles.find((r) => r.companies.includes(targetCompany));
  const res = role?.permissions.includes(targetPermission);
  return res;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Dict
checkPermissionDict()
ready
Loop
checkPermissionLoop()
ready

Revisions

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