while vs floor

Benchmark created on


Description

comparing a while loop and floor based flooring for numbers

Setup

function floorImp(M) {
    return M - Math.floor(M);
}


function whileImp(M) {
    while (M > 1) {
        M -= 1;
    }
    while (M < 0) {
        M += 1;
    }
  return M
}

const getRand = () => Math.random() * 2 -1

Test runner

Ready to run.

Testing in
TestOps/sec
Floor implementation (Big number)
floorImp(100_000 * getRand())
ready
While implementation (Big number)
whileImp(100_000 * getRand())
ready
Floor implementation (Small number)
floorImp(360 * getRand())
ready
While implementation (Small number)
whileImp(360 * getRand())
ready

Revisions

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