Rounding comparison

Benchmark created on


Setup

let x = [Math.random() * 100, Math.random() * 100, Math.random() * 100, Math.random() * 100];

let y = [Math.random() * 100, Math.random() * 100, Math.random() * 100, Math.random() * 100];
let z = false;

Test runner

Ready to run.

Testing in
TestOps/sec
Math.round
let i = Math.round(x[0]) === Math.round(y[0]) ||
Math.round(x[1]) === Math.round(y[1]) ||
Math.round(x[2]) === Math.round(y[2]) ||
Math.round(x[3]) === Math.round(y[3]);
z ||= i;
ready
Shift
let i = (x[0]>> 0) === (y[0]>> 0) ||
(x[1]>> 0) === (y[1]>> 0) ||
(x[2]>> 0) === (y[2]>> 0) ||
(x[3]>> 0) === (y[3]>> 0);
z ||= i;
ready
Trunc
let i = Math.trunc(x[0]) === Math.trunc(y[0]) ||
Math.trunc(x[1]) === Math.trunc(y[1]) ||
Math.trunc(x[2]) === Math.trunc(y[2]) ||
Math.trunc(x[3]) === Math.trunc(y[3]);
z ||= i;
ready

Revisions

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