Clamp

Benchmark created on


Setup

function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
}


const A = getRandomArbitrary(-Number.MAX_SAFE_INTEGER, 0)

const B = getRandomArbitrary(1, Number.MAX_SAFE_INTEGER)


const C = getRandomArbitrary(-Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)

Test runner

Ready to run.

Testing in
TestOps/sec
Min First
Math.min(Math.max(C, A), B);
ready
Max First
Math.max(B, Math.min(C, A));
ready

Revisions

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