Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Safari/605.1.15
Safari 18
Mac OS X 10.15.7
Desktop
2 months ago
Test name Executions per second
string enums 7693.1 Ops/sec
numeric enums 10269.8 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++;
        }
    }