# Cantor Szudzik Pair Comparison

## JavaScript performance comparison

Revision 3 of this test case created by Steven Sell

## Preparation code

``````

<script>
Benchmark.prototype.setup = function() {
function cantorPair(x, y)
{
return ((x + y) * (x + y + 1)) * 0.5 + y;
}

function cantorPairSigned(x, y)
{
const a = (x >= 0.0 ? 2.0 * x : (-2.0 * x) - 1.0);
const b = (y >= 0.0 ? 2.0 * y : (-2.0 * y) - 1.0);
return cantorPair(a, b);
}

function szudzikPair(x, y)
{
return (x >= y ? (x * x) + x + y : (y * y) + x);
}

function szudzikPairSignedA(x, y)
{
const a = (x >= 0.0 ? 2.0 * x : (-2.0 * x) - 1.0);
const b = (y >= 0.0 ? 2.0 * y : (-2.0 * y) - 1.0);
return szudzikPair(a, b) / 2;
}

function szudzikPairSignedB(x, y)
{
const a = (x >= 0.0 ? 2.0 * x : (-2.0 * x) - 1.0);
const b = (y >= 0.0 ? 2.0 * y : (-2.0 * y) - 1.0);
const c = szudzikPair(a, b) / 2;

if(((a >= 0.0) && (b < 0.0)) || ((a < 0.0) && (b >= 0.0))) {
return -c - 1;
}

return c;
}
};

</script>
``````

## Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Cantor
``cantorPair(13, 117);``
pending…
Cantor Signed
``cantorPairSigned(13, 117);``
pending…
Szudzik Signed A
``szudzikPairSignedA(13, 117);``
pending…
Szudzik Signed B
``szudzikPairSignedB(13, 117);``
pending…
Szudzik
``szudzikPair(13, 117);``
pending…

## Revisions

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