Is There A Difference Between Symbol & Function Pointer Comparison?

Benchmark created on


Setup

const TEST_SIZE = 10_000;
const syms = Array.from({length: TEST_SIZE}, (_, ix) => Symbol())
const fnps = Array.from({length: TEST_SIZE}, (_, ix) => function (a) { return a; })

const samples = Array.from({length: Math.trunc(TEST_SIZE / 10)}, (_, ix) => Math.trunc(ix * 10))

Test runner

Ready to run.

Testing in
TestOps/sec
Function Comparison
let is = 0, ia = 0, result = 0;

for (; is < samples.length; is++) {
	ia = 0;
	for (; ia < fnps.length; ia++) {
		if (fnps[is] === fnps[ia]) {
			result++;
		}
	}
	
}
ready
Symbol Comparison
let is = 0, ia = 0, result = 0;

for (; is < samples.length; is++) {
	ia = 0;
	for (; ia < syms.length; ia++) {
		if (syms[is] === syms[ia]) {
			result++;
		}
	}
	
}
ready

Revisions

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