Javascript Objects vs Map performance (v2)

Revision 2 of this benchmark created on


Setup

  const issuers = [{
        kid: 'WMCtWxtaE-lr5XhooW3_uILcAMiAVxdjlVspENRgl14',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHSRzBNLuCNN4V4J+VRkdaXg9bl5\n' +
            '562bKSa27Tp5DzvLPJtp6Pa9riyse2sq3WJPN9A4FLkqC4jko4uS4/YWfBTYbTDc\n' +
            'T8hf3vIEwGR7psaR1k3dRA6r5EtpUY3ZVa46YIAECpqkNq+X6NGzOmRoARbbbaUm\n' +
            'lqtAX7H+2i60TgnrAgMBAAE=\n' +
            '-----END PUBLIC KEY-----',
        algorithm: 'RS256',
    },
    {
        kid: '8Jv_Rm5FWs9gKbT_gMQ5Yh4IF3Eq3kkCCQx5yokQorY',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwywboZjMMbtJMD8SuXPj\n' +
            'rhT+QE5tbq2GFLWbBuV+JRXwF5UOHhGS/ueLX9HH8XqySdbMGdKFRdx1dCF0axOM\n' +
            'w/lznzGMAekWaBH6uYbMhT8wux3+3YOlKDccX9ByKSwwvdGyFs+60wGldjLZz6vA\n' +
            'PuGARqTvXX/5SL+iUTHn99mtC+2W/RpfuX6FjvFnWSFaEZwdXbM93ck/GgBTuVjd\n' +
            'PxiDXQ9OtjUVv9Nxt1okr/PvxqxpzDJ+MBIbuwQAhRBUUSwMazQxxVPX1e3H7zq8\n' +
            '2DEE6RJ9e3oiuGs+h3pmf43i4fH3gasvMN/p6fYv/Rvk5DzGIpiQJ73xMYEdXsVt\n' +
            'PQIDAQAB\n' +
            '-----END PUBLIC KEY-----',
        algorithm: 'RS256',
    }, {
        kid: '5QAdx1FjJGHmSjE4nrniy',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6JbP4kUfBIpYDYja7ptp\n' +
            'ikPoM7yTwGdaCF28fyLwsJmJeaWJjDtaJFwa1wn74/231q/YWzDSZF83og7r15mX\n' +
            'xTeqaQWhEG26c9JsmQRraFJOa2dukXwPcsioRZz4COGrmVZt6IZe8qdU7eqwx+cI\n' +
            'yhFP5H+fnvWcXwDEqu6GPAvHgeZmZvQxRqc+QDXpUecWbmyGP+UquCNOnGC13d4t\n' +
            'm31bSGcFnmJbRMRZ5ljK4TEoRsc1oBi8i3X/WQygiwDko8rn+cusJQ/7I/TerC4I\n' +
            '9t5Be4A+3wIWRlSyynvm4kkH/8V7YtLNnmOb2ltkXEHBOSzJLEwXQvv1ayGlHVvj\n' +
            'hQIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    },
    {
        kid: '17R_34DHgF9Ewtkrt7ON7',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAveXF7ZfJapCaZa2lFgao\n' +
            'DNZ1byBAftRZHLb+e+V5E93QPw+dM23Y7FP5QOINdpbBysBsqAXviIBXkorkMKWh\n' +
            'yGnVK/HZv27nzThZgWQpZ4ggi8rliBgjMDWBoO+vvZhhFOvLJ1fqyOB5Urt1vlXf\n' +
            'N+Ud3b7mM2FS0Bi0ZedufYXL5eBZl22Hmf6KxI7zlBgnj7nROUuAspAUlxAlekZp\n' +
            'MD+gYFRI8Xc3k6gMOixFLjGaXKYcy++p6uUJpz/mV3hVY/0tIVy9jg6qzG4Zyr2z\n' +
            'MCZwNTg5y81WwPJT/1JxXXHqVThgou7g1OIoi/I8cDwHWUrg+kyohedsdGEU+P0D\n' +
            'JQIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    },{
        kid: 'ET08_rHkbmoZBI-6VorIh',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Tak8wjVHhnv2wX6ma3b\n' +
            'k81COkgVSLXCIk5WG+w3NKZMrnQjA5ZJ2UpyGM73D0zFvf6nQ43SBLZzK4LLLXdi\n' +
            'rY3BbSzDxmbf+PwOrbnJ6tvgflNIpljIgoFktRJ4gYkiFmhCpqD7inq3tsqeh3na\n' +
            'sGPuJP7M4sxb5X005Oly9lxr/FZsceQE0ic4/d+IXszU3XNuwCXRxc0zDxB0kQnj\n' +
            'm81Yhg5CznHx103QeL0ZyYeZojxlxIMNRwR7kA0w2L3HW0YsJefeHaw7wA2aM8b2\n' +
            'ObZYrOoBtKbfZ9/B+L4oWlZi1ZBqEHu1dQcVGAaVYfpTgkste/S9ouleIU2nbC+S\n' +
            'vwIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    },
    {
        kid: 'mb-2ie0VDE0BHpfhrvSQp',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3iieNJe5Vr/lT3b1ZcjZ\n' +
            '8ev8PvA1/VEnk12BOX75SWzHBY5Pp0OY9Nrt0PfZ7NgkKTX9X/25ZoyUKZzs/y2H\n' +
            'XCThmDBuaCowmCfoJJE24nwTDu61f6S1jDn1xRB/SJqq6wVwDb2LbLKvMLy+5Gkm\n' +
            'VYHSmlsOWKa+INDWTmhT/eMF78uFxe/PGneyxE6cu0Zs5TMFl+kR+D8eDrZYeJdv\n' +
            'ID6XoUlzxmVNqHylojVI9Bvg9WjRiVM/YRXjpDqpBXNkdrsdsxZSX6xczalGtufe\n' +
            'l/g6lwcGPI5RBoI6GwLfvgJm8unhmJrp0k5QOzgFgJifOiqu14VYSPkf8nGo4qYi\n' +
            '4wIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    },];
  
  const issuerMap = new Map();
  for (const issuer of issuers) {
  	issuerMap.set(issuer.kid, issuer);
  }
  
  const issuerObjectFromEntries = Object.fromEntries(issuers.map((i) => [i.kid, i]));
  
  const issuerObjectLiteral = {
  	'WMCtWxtaE-lr5XhooW3_uILcAMiAVxdjlVspENRgl14': {
        kid: 'WMCtWxtaE-lr5XhooW3_uILcAMiAVxdjlVspENRgl14',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHSRzBNLuCNN4V4J+VRkdaXg9bl5\n' +
            '562bKSa27Tp5DzvLPJtp6Pa9riyse2sq3WJPN9A4FLkqC4jko4uS4/YWfBTYbTDc\n' +
            'T8hf3vIEwGR7psaR1k3dRA6r5EtpUY3ZVa46YIAECpqkNq+X6NGzOmRoARbbbaUm\n' +
            'lqtAX7H+2i60TgnrAgMBAAE=\n' +
            '-----END PUBLIC KEY-----',
        algorithm: 'RS256',
    },
    '8Jv_Rm5FWs9gKbT_gMQ5Yh4IF3Eq3kkCCQx5yokQorY': {
        kid: '8Jv_Rm5FWs9gKbT_gMQ5Yh4IF3Eq3kkCCQx5yokQorY',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwywboZjMMbtJMD8SuXPj\n' +
            'rhT+QE5tbq2GFLWbBuV+JRXwF5UOHhGS/ueLX9HH8XqySdbMGdKFRdx1dCF0axOM\n' +
            'w/lznzGMAekWaBH6uYbMhT8wux3+3YOlKDccX9ByKSwwvdGyFs+60wGldjLZz6vA\n' +
            'PuGARqTvXX/5SL+iUTHn99mtC+2W/RpfuX6FjvFnWSFaEZwdXbM93ck/GgBTuVjd\n' +
            'PxiDXQ9OtjUVv9Nxt1okr/PvxqxpzDJ+MBIbuwQAhRBUUSwMazQxxVPX1e3H7zq8\n' +
            '2DEE6RJ9e3oiuGs+h3pmf43i4fH3gasvMN/p6fYv/Rvk5DzGIpiQJ73xMYEdXsVt\n' +
            'PQIDAQAB\n' +
            '-----END PUBLIC KEY-----',
        algorithm: 'RS256',
    }, '5QAdx1FjJGHmSjE4nrniy': {
        kid: '5QAdx1FjJGHmSjE4nrniy',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6JbP4kUfBIpYDYja7ptp\n' +
            'ikPoM7yTwGdaCF28fyLwsJmJeaWJjDtaJFwa1wn74/231q/YWzDSZF83og7r15mX\n' +
            'xTeqaQWhEG26c9JsmQRraFJOa2dukXwPcsioRZz4COGrmVZt6IZe8qdU7eqwx+cI\n' +
            'yhFP5H+fnvWcXwDEqu6GPAvHgeZmZvQxRqc+QDXpUecWbmyGP+UquCNOnGC13d4t\n' +
            'm31bSGcFnmJbRMRZ5ljK4TEoRsc1oBi8i3X/WQygiwDko8rn+cusJQ/7I/TerC4I\n' +
            '9t5Be4A+3wIWRlSyynvm4kkH/8V7YtLNnmOb2ltkXEHBOSzJLEwXQvv1ayGlHVvj\n' +
            'hQIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    },
    '17R_34DHgF9Ewtkrt7ON7': {
        kid: '17R_34DHgF9Ewtkrt7ON7',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAveXF7ZfJapCaZa2lFgao\n' +
            'DNZ1byBAftRZHLb+e+V5E93QPw+dM23Y7FP5QOINdpbBysBsqAXviIBXkorkMKWh\n' +
            'yGnVK/HZv27nzThZgWQpZ4ggi8rliBgjMDWBoO+vvZhhFOvLJ1fqyOB5Urt1vlXf\n' +
            'N+Ud3b7mM2FS0Bi0ZedufYXL5eBZl22Hmf6KxI7zlBgnj7nROUuAspAUlxAlekZp\n' +
            'MD+gYFRI8Xc3k6gMOixFLjGaXKYcy++p6uUJpz/mV3hVY/0tIVy9jg6qzG4Zyr2z\n' +
            'MCZwNTg5y81WwPJT/1JxXXHqVThgou7g1OIoi/I8cDwHWUrg+kyohedsdGEU+P0D\n' +
            'JQIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    },'ET08_rHkbmoZBI-6VorIh': {
        kid: 'ET08_rHkbmoZBI-6VorIh',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Tak8wjVHhnv2wX6ma3b\n' +
            'k81COkgVSLXCIk5WG+w3NKZMrnQjA5ZJ2UpyGM73D0zFvf6nQ43SBLZzK4LLLXdi\n' +
            'rY3BbSzDxmbf+PwOrbnJ6tvgflNIpljIgoFktRJ4gYkiFmhCpqD7inq3tsqeh3na\n' +
            'sGPuJP7M4sxb5X005Oly9lxr/FZsceQE0ic4/d+IXszU3XNuwCXRxc0zDxB0kQnj\n' +
            'm81Yhg5CznHx103QeL0ZyYeZojxlxIMNRwR7kA0w2L3HW0YsJefeHaw7wA2aM8b2\n' +
            'ObZYrOoBtKbfZ9/B+L4oWlZi1ZBqEHu1dQcVGAaVYfpTgkste/S9ouleIU2nbC+S\n' +
            'vwIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    },
    'mb-2ie0VDE0BHpfhrvSQp': {
        kid: 'mb-2ie0VDE0BHpfhrvSQp',
        publicKey:
            '-----BEGIN PUBLIC KEY-----\n' +
            'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3iieNJe5Vr/lT3b1ZcjZ\n' +
            '8ev8PvA1/VEnk12BOX75SWzHBY5Pp0OY9Nrt0PfZ7NgkKTX9X/25ZoyUKZzs/y2H\n' +
            'XCThmDBuaCowmCfoJJE24nwTDu61f6S1jDn1xRB/SJqq6wVwDb2LbLKvMLy+5Gkm\n' +
            'VYHSmlsOWKa+INDWTmhT/eMF78uFxe/PGneyxE6cu0Zs5TMFl+kR+D8eDrZYeJdv\n' +
            'ID6XoUlzxmVNqHylojVI9Bvg9WjRiVM/YRXjpDqpBXNkdrsdsxZSX6xczalGtufe\n' +
            'l/g6lwcGPI5RBoI6GwLfvgJm8unhmJrp0k5QOzgFgJifOiqu14VYSPkf8nGo4qYi\n' +
            '4wIDAQAB\n' +
            '-----END PUBLIC KEY-----\n',
        algorithm: 'RS256',
    }
  };

const earlyKid = 'WMCtWxtaE-lr5XhooW3_uILcAMiAVxdjlVspENRgl14';

const middleKid = '17R_34DHgF9Ewtkrt7ON7';

const finalKid = 'mb-2ie0VDE0BHpfhrvSQp';

const nullKid = undefined;

const badKid = 'asdf';

Test runner

Ready to run.

Testing in
TestOps/sec
Lookup kid from Map (early match)
console.log(issuerMap.get(earlyKid));
ready
Lookup kid from Map (middle match)
console.log(issuerMap.get(middleKid));
ready
Lookup kid from Map (late match)
console.log(issuerMap.get(finalKid));
ready
Lookup kid from Map (no match)
console.log(issuerMap.get(badKid));
ready
Lookup kid from Map (null)
console.log(issuerMap.get(nullKid));
ready
Lookup kid from Object fromEntries (early match)
console.log(issuerObjectFromEntries[earlyKid]);
ready
Lookup kid from Object fromEntries (middle match)
console.log(issuerObjectFromEntries[middleKid]);
ready
Lookup kid from Object fromEntries (late match)
console.log(issuerObjectFromEntries[finalKid]);
ready
Lookup kid from Object fromEntries (no match)
console.log(issuerObjectFromEntries[badKid]);
ready
Lookup kid from Object fromEntries (null)
console.log(issuerObjectFromEntries[nullKid]);
ready
Lookup kid from object literal (early match)
console.log(issuerObjectLiteral[earlyKid]);
ready
Lookup kid from object literal (middle match)
console.log(issuerObjectLiteral[middleKid]);
ready
Lookup kid from object literal (late match)
console.log(issuerObjectLiteral[finalKid]);
ready
Lookup kid from object literal (no match)
console.log(issuerObjectLiteral[badKid]);
ready
Lookup kid from object literal (null)
console.log(issuerObjectLiteral[nullKid]);
ready

Revisions

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