Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0
Firefox 133
Mac OS X 10.15
Desktop
2 months ago
Test name Executions per second
string enums 3242.5 Ops/sec
numeric enums 4310.5 Ops/sec
Tests:
  • string enums

    x
     
    const a = {
        one: 'one',
        two: 'two',
    };
    let c = 0;
    for (let i = 0; i < 100000; i++) {
        const v = i % 2 === 0 ? a.one : a.two;
        if (v === a.one) {
            c++;
        }
    }
  • numeric enums

     
    const a = {
        one: 1,
        two: 2,
    };
    let c = 0;
    for (let i = 0; i < 100000; i++) {
        const v = i % 2 === 0 ? a.one : a.two;
        if (v === a.one) {
            c++;
        }
    }