rect perf (v3)

Revision 3 of this 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 getResults() {
  return results;
}

const counter = {value: 0};
function getCounter() {
	return counter;
}
</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();

const counter = getCounter();
getResults()[counter.value++ % 10] = createObject(x, y, width, height);
ready
rect
const x = Math.random();
const y = Math.random();
const width = Math.random();
const height = Math.random();

const counter = getCounter();
getResults()[counter.value++ % 10] = 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;

const counter = getCounter();
getResults()[counter.value++ % 10] = {
  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.