Test types

Benchmark created on


Setup

function __add__A(a,b){ return a+b }

function * genA(beg, end, step) {
	if(false) // >= 32 not supported
	    throw new Error("Not implemented !")
	for(let iter = beg; iter < end; iter+=step)
	    yield iter;
}


/****************************/
function __add__B(a,b){ return a+b }

function * genB(beg, end, step) {
	if(false) // >= 32 not supported
	    throw new Error("Not implemented !")
	for(let iter = beg; iter < end; iter+=step)
	    yield iter;
}

/****************************/
function __inplace_add__C(a,b){
	a[0] += b[0];
	return a }

function * genC(beg, end, step) {
	if(false) // >= 32 not supported
	    throw new Error("Not implemented !")
	const a = new BigInt64Array(3)
	a[0] = beg;
	const _end = a[1] = end;
	const _step = a[2] = step;
	const iter = new BigInt64Array(1)
	for( ; a[0] < _end; a[0]+=_step) {
		iter[0] = a[0]; // need to copy
	    yield iter;
	}
}

/****************************/
function __inplace_add__D(a,b){
	a[0] += b[0];
	return a }

function * genD(beg, end, step) {
	if(false) // >= 32 not supported
	    throw new Error("Not implemented !")
	const a = new Int32Array(3)
	const iter = new Int32Array(1)
	a[0] = beg;
	const _end = a[1] = end;
	const _step = a[2] = step;
	for( ; a[0] < _end; a[0]+=_step) {
		iter[0] = a[0]; // need to copy
	    yield iter;
	}
}



/****************************/
function __inplace_add__E(a,b){
	a[0] += b[0];
	return a }

function * genE(beg, end, step) {
	if(false) // >= 32 not supported
	    throw new Error("Not implemented !")
	const a = new Float64Array(3)
	const iter = new Float64Array(1)
	a[0] = beg;
	const _end = a[1] = end;
	const _step = a[2] = step;
	for( ; a[0] < _end; a[0]+=_step) {
		iter[0] = a[0]; // need to copy
	    yield iter;
	}
}

/****************************/
function __inplace_add__F(a,b){
	a.value[0] += b.value[0];
	return a }

function * genF(beg, end, step) {
	if(false) // >= 32 not supported
	    throw new Error("Not implemented !")
	const a = [beg, end, step];
	let iter = {type: "integer", value:[0]}
	let i = a[0]
	const _end = a[1] = end;
	const _step = a[2] = step;
	for( ; i < _end; i += _step ) {
		iter.value[0] = i; // need to copy
	    yield iter;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Native
let acc = 0
for(let i of genA(0,100000,2) )

    acc = __add__A(acc, i)
    

console.log(acc)
ready
BigInt
let acc = 0n
for(let i of genB(0n,100000n,2n) )

    acc = __add__B(acc, i)
    

console.log(acc)
ready
BigInt64Array
let acc = new BigInt64Array([0n]);

for(let i of genC(0n,100000n,2n) )

    __inplace_add__C(acc, i)
    

console.log(acc)
ready
Int32Array
let acc = new Int32Array([0])

for(let i of genD(0,100000,2) )

    __inplace_add__D(acc, i)
    

console.log(acc)
ready
Float64Array
let acc = new Float64Array([0])

for(let i of genE(0,100000,2) )

    __inplace_add__E(acc, i)
    

console.log(acc)
ready
Array struct
let acc = {
	type: "integer",
	value: [0]
}

for(let i of genF(0,100000,2) )

    __inplace_add__F(acc, i)
    

console.log(acc)
ready

Revisions

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