fallthrough (v4)

Revision 4 of this benchmark created on


Setup

const propertyValues = {
	red: 123
};

const color = "red";
const angle = "front";
const colorAngle = "red+front";
const defaultValue = 1;
let value = 0;

const keys = [colorAngle, angle, color];

Test runner

Ready to run.

Testing in
TestOps/sec
nullish
value = 
(propertyValues[colorAngle]) ??
(propertyValues[angle]) ??
(propertyValues[color]) ??
defaultValue;
ready
forloop
gettit: {
  for (const key of keys) {
  	const v = propertyValues[key];
  	if (v !== undefined) { value = v; break gettit; }
  }
  value = defaultValue;
}
ready
nested if
const v1 = propertyValues[colorAngle];
if (v1 === undefined) {
  const v2 = propertyValues[angle];
  if (v2 === undefined) {
    const v3 = propertyValues[color];
    if (v3 === undefined) {
      value = valueDefault;
    } else {
      value = v3;
    }
  } else {
    value = v2;
  }
} else {
  value = v1;
}
ready
nested if loose
const v1 = propertyValues[colorAngle];
if (v1 == null) {
  const v2 = propertyValues[angle];
  if (v2 == null) {
    const v3 = propertyValues[color];
    if (v3 == null) {
      value = valueDefault;
    } else {
      value = v3;
    }
  } else {
    value = v2;
  }
} else {
  value = v1;
}
ready

Revisions

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