jsSquare

Benchmark created on


Setup

function jsSquare(number) {
    let result = 1;
    let base = number;
    let exponent = 2; // Squaring, so the exponent is 2

    while (exponent > 0) {
        if (exponent & 1) {
            result *= base;
        }
        base *= base;
        exponent >>= 1; // Right shift the exponent to process the next bit
    }

    return result;
}

Test runner

Ready to run.

Testing in
TestOps/sec
jsSquare
jsSquare(999_999_999)
ready
mathSquare
Math.pow(999_999_999, 2)
ready
doubleAst
999_999_999**2
ready
selfMulti
999_999_999*999_999_999
ready

Revisions

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