Cantor vs toString() vs Manual string

Benchmark created on


Setup

const r = () => Math.round(Math.random() * 1000) - 500;
const points = [];
for (let i = 0; i < 10000; i++) {
    points.push([r(), r()]);
}
const cantor = (x, y) => (((x + y) * (x + y + 1)) / 2) + y;

Test runner

Ready to run.

Testing in
TestOps/sec
Cantor
for (const p of points) {
    const result = cantor(p[0], p[1]);
}
ready
toString()
for (const p of points) {
    const result = p.toString();
}
ready
Manual String
for (const p of points) {
    const result = `${p[0]},${p[1]}`;
}
ready

Revisions

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