Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131
Windows
Desktop
2 months ago
Test name Executions per second
string enums 20741.6 Ops/sec
numeric enums 21665.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++;
        }
    }