compiled vs mine

Benchmark created by David on


Test runner

Ready to run.

Testing in
TestOps/sec
Minified
function power(c, a) {
    if (0 === a) {
        return 1;
    }
    if (2 > c) {
        return c;
    }
    for (var d = 1, b = c;; b *= b) {
        0 !== a % 2 && (d *= b);
        if ((a /= 2) >>> 0 !== a) {
            a = 0;
        }
        if (0 === a) {
            break;
        }
    }
    return d;
}
ready
Mine
function power(base, exponent) {
    if (exponent === 0) {
        return 1;
    }
    if (base < 2) {
        return base;
    }

    var result = 1;

    for (var term = base;; term = term * term) {
        if (exponent % 2 !== 0) {
            result *= term;
        }
        exponent /= 2;
        if (exponent >>> 0 !== exponent) {
            exponent = 0;
        }
        if (exponent === 0) {
            break;
        }
    }
}
ready

Revisions

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

  • Revision 1: published by David on