Bitwise XOR vs logical !=

Benchmark created on


Description

Comparing a bitwise + conversion XOR to a logical !=

Setup

class Texture {
  constructor() {
    this._value = 0;
  }

  get value() { return this._value }
  set value(s) { this._value = s}
}

class Image extends Texture {
  constructor() {
    super();
    this._value = 1;
  }
}

const texture = new Image();

const textureOptions = {
  flipY: false
}

Test runner

Ready to run.

Testing in
TestOps/sec
Bitwise XOR
let flipY = 0
// convert to integer for bitwise operation below
flipY = +(textureOptions.flipY || 0);

if (flipY ^ +(texture instanceof Texture)) {
  let value = 1;
}
ready
Logical !=
// Assign boolean value for flipY
flipY = textureOptions.flipY || false;

if (flipY != (texture instanceof Texture)) {
  let value = 1;
}
ready

Revisions

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