Bitwise vs boolean flags (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var a = {
   bitwise: 0x0012,
   flag: true,
   int: 1,
  };
  
  var t = {
   bitwise: 0x0002
  };
  
  var i = 0;
  var j = 0;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Bitwise Mix
if (a.bitwise & t.bitwise) {
 i = (i + 1) % 10;
} else {
 j = 1;
}
a.bitwise &= ~t.bitwise;
if (a.bitwise & t.bitwise) {
 j = 2;
} else {
 i = (i + 1) % 10;
}
a.bitwise |= t.bitwise;
if (a.bitwise & t.bitwise) {
 i = (i + 1) % 10;
} else {
 j = 3;
}
ready
Flag Mix
if (a.flag) {
 i = (i + 1) % 10;
} else {
 j = 1;
}
a.flag = false;
if (a.flag) {
 j = 2;
} else {
 i = (i + 1) % 10;
}
a.flag = true;
if (a.flag) {
 i = (i + 1) % 10;
} else {
 j = 3;
}
ready
Int Mix 3
if (a.int === 1) {
 i = (i + 1) % 10;
} else {
 j = 1;
}
a.int = 0;
if (a.int === 1) {
 j = 2;
} else {
 i = (i + 1) % 10;
}
a.int = 1;
if (a.int === 1) {
 i = (i + 1) % 10;
} else {
 j = 3;
}
ready
Int Mix 2
if (a.int == 1) {
 i = (i + 1) % 10;
} else {
 j = 1;
}
a.int = 0;
if (a.int == 1) {
 j = 2;
} else {
 i = (i + 1) % 10;
}
a.int = 1;
if (a.int == 1) {
 i = (i + 1) % 10;
} else {
 j = 3;
}
ready
Int Mix
if (a.int) {
 i = (i + 1) % 10;
} else {
 j = 1;
}
a.int = 0;
if (a.int) {
 j = 2;
} else {
 i = (i + 1) % 10;
}
a.int = 1;
if (a.int) {
 i = (i + 1) % 10;
} else {
 j = 3;
}
ready
Flag mix 2
if (a.flag == true) {
 i = (i + 1) % 10;
} else {
 j = 1;
}
a.flag = false;
if (a.flag == true) {
 j = 2;
} else {
 i = (i + 1) % 10;
}
a.flag = true;
if (a.flag == true) {
 i = (i + 1) % 10;
} else {
 j = 3;
}
ready

Revisions

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