rect perf

Benchmark created on


Preparation HTML

<script>
function createObject(
  x,
  y,
  width,
  height
) {
  const top = height >= 0 ? y : y + height;
  const right = width >= 0 ? x + width : x;
  const bottom = height >= 0 ? y + height : y;
  const left = width >= 0 ? x : x + width;
 
  return {
    x,
    y,
    width,
    height,
    top,
    right,
    bottom,
    left,
  };
}

class MyRect extends DOMRect{};

const results = [[],[],[]];

function getResults1() {
  return results[0];
}
function getResults2() {
  return results[1];
  }
function getResults3() {
  return results[2];
}

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
factory
const x = Math.random();
const y = Math.random();
const width = Math.random();
const height = Math.random();

getResults1().push((createObject(x, y, width, height)));
ready
rect
const x = Math.random();
const y = Math.random();
const width = Math.random();
const height = Math.random();

getResults2().push(new MyRect(x, y, width, height))
ready
plain
const x = Math.random();
const y = Math.random();
const width = Math.random();
const height = Math.random();

const top = height >= 0 ? y : y + height;
const right = width >= 0 ? x + width : x;
const bottom = height >= 0 ? y + height : y;
const left = width >= 0 ? x : x + width;

getResults3().push({
  x,
  y,
  width,
  height,
  top,
  right,
  bottom,
  left,
});
ready

Revisions

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