XOR implementations

Benchmark created by Bryan Elliott on


Preparation HTML

<script>
Boolean.prototype.xorBitwiseCast = function (b) {
        return !!(this ^ b);
};
Boolean.prototype.xorBoolOnly = function (b) {
        return ((this || b) && !(this && b));
};
Boolean.prototype.xorEquivalence = function (b) {
        return this !== !!b;
};
Boolean.prototype.xorTernary = function (b) {
        return this ? !b : b;
};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
XOR by bitwise cast
true .xorBitwiseCast(true);
true .xorBitwiseCast(false);
false.xorBitwiseCast(true);
false.xorBitwiseCast(false);
ready
XOR by classical definition
true .xorBoolOnly(true);
true .xorBoolOnly(false);
false.xorBoolOnly(true);
false.xorBoolOnly(false);
ready
XOR by equivalence
true .xorEquivalence(true);
true .xorEquivalence(false);
false.xorEquivalence(true);
false.xorEquivalence(false);
ready
XOR by ternary
true .xorTernary(true);
true .xorTernary(false);
false.xorTernary(true);
false.xorTernary(false);
ready

Revisions

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

  • Revision 1: published by Bryan Elliott on