superFloor (v2)

Revision 2 of this benchmark created on


Setup

const testNumbers = [];
for (let i = 0; i < 1000000; ++i) {
	testNumbers.push(Math.random() * 10)
}

function test() {
    let sum = 0;
    for (const i of testNumbers) {
        sum += superFloor(i);
    }
    console.log(sum);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Manual Implementation
function superFloor(x) {
    if (Number.isInteger(x)) {
        return x - 1;
    } else {
        return Math.floor(x);
    }
}

test();
ready
With Ceil
function superFloor(x) {
    return Math.ceil(x) - 1;
}

test();
ready
With Ceil (inner subtraction)
function superFloor(x) {
    return Math.ceil(x - 1);
}

test();
ready

Revisions

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