BigInt vs Integer (v3)

Revision 3 of this benchmark created on


Setup

/**
 * Pros: 
 * Cons:
 *  - Slow
 *  - Not uniform (there are more items in slot 0|0 than any other slot)
 */
function ParseIntHash(x, y) {
	x = parseInt(x) - (parseInt(x) % 8);
	y = parseInt(y) - (parseInt(y) % 8);
	return x + "|" + y;
}
/**
 * Pros:
 *  - Fast
 * Cons:
 *  - Non-uniform (there are more items in slot 0|0 than any other slot)
 */
function TruncIntHash(x, y) {
	x = Math.trunc(x) - (Math.trunc(x) % 8);
	y = Math.trunc(y) - (Math.trunc(y) % 8);
	return x + "|" + y;
}
/**
 * Pros:
 *  - Fast
 *  - Uniform (same number of items in every slot)
 * Cons:
 */
function BestBoiHash(x, y) {
	return (x >> 3) + "|" + (y >> 3);
}
var X = Math.random() * 1000 - 500;
var Y = Math.random() * 1000 - 500;
var RESULT = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Parse Integer
RESULT = ParseIntHash(X, Y);
ready
Trunc Integer
RESULT = TruncIntHash(X, Y);
ready
Best Boi Hash
RESULT = BestBoiHash(X, Y);
ready

Revisions

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