square brackets vs at

Benchmark created on


Setup

function generateRandomWord(length) {
    let result = '';
    const characters = 'abcdefghijklmnopqrstuvwxyz';
    for (let i = 0; i < length; i++) {
        result += characters.charAt(Math.floor(Math.random() * characters.length));
    }
    return result;
}

const testLen = 1000;

const words = Array.from({ length: testLen }, () => generateRandomWord(5));

Test runner

Ready to run.

Testing in
TestOps/sec
square brackets []
const word = words[testLen-10]
ready
at()
const word = words.at(testLen-10);
ready

Revisions

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