Array vs hex vs number (v2)

Revision 2 of this benchmark created on


Setup

function assign(x, y){
	if(y > N)
	     throw new Error('Outbound at', y);
	return x*x;
}
function assugn(y, x){
	if(y > N)
	     throw new Error('Outbound at', y);
	return x*x;
}
const N = 10000

Test runner

Ready to run.

Testing in
TestOps/sec
array
let tot = 0;
for(var i=0;i<N;i++){
	tot += assign(i, [1, 2, 3])
}
console.log(tot)
ready
hex
let tot = 0;
for(var i=0;i<N;i++){
	tot+=assign(i, 0x13A)
}
console.log(tot)
ready
number
tot = 0;
for(var i=0;i<N;i++){
	tot+=assign(i, 314)
}
console.log(tot)
ready
Invert hex
tot = 0;
for(var i=0;i<N;i++){
	tot+=assugn(0x13A, i)
}
console.log(tot)
ready
Invert num
tot = 0;
for(var i=0;i<N;i++){
	tot+=assugn(314, i)
}
console.log(tot)
ready

Revisions

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