ParseInt vs Trunc vs BestBoi (v5)

Revision 5 of this benchmark created on


Description

Comparison of assorted point hash functions

Setup

/**
 * Pros: 
 *  - Human Readable hash (But does it really need to be human readable?)
 * 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:
 *  - Human Readable hash (But does it really need to be human readable?)
 *  - 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:
 *  - Human Readable hash (But does it really need to be human readable?)
 *  - 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.