Test loop (v2)

Revision 2 of this benchmark created on


Setup

let CONVERTOR = new BigInt64Array(1)

function __lesser__(i, end){
	return i.value < end.value;
}

function __impl_add__(i, step) {
	i.value += step.value
	return {type:"int", value: i.value}
}
function __mod__(i, step) {
	return {type:"int", value: i.value % step.value }
}1

Test runner

Ready to run.

Testing in
TestOps/sec
For loop
let acc = 0;
let i = 0
for(; i < 10000; i+=2)
    if( i % 4 )
        ++acc;
    
console.log(acc, i);
ready
Bigint
let acc = 0;
let i = 0n
for(; i < 10000n; i+=2n)
    if( i % 4n)
        ++acc;
    
console.log(acc, i);
ready
BigIntArray
const data  = new BigInt64Array(3)
let iter = data[0] = 0n
const end  = data[1] = 10000n
const step = data[2] = 2n
let i = data[0]

let acc = 0;
const n4 = CONVERTOR[0] = 4n

for( ; iter < end; i = iter+=step)
      if( i % n4 )
          ++acc;
      
console.log(acc, iter)
ready
BigIntArray II
let data  = new BigInt64Array(4)
data[0] = 0n
const end  = data[1] = 10000n
const step = data[2] = 2n

const n4 = CONVERTOR[0] = 4n
let acc = 0;

for( ; data[0] < end; data[3] = data[0]+=step)
      if( data[3] % n4 )
          ++acc;
      
console.log(acc, data[0])
ready
For loop i is bigint
let acc = 0;
let i = 0
for(; i < 10000; i+=2)
    if( BigInt(i) % 4n )
        ++acc;
    
console.log(acc, i);
ready
For loop i is BigInt64Array
let acc = 0;
let i = new BigInt64Array(3)
const n = i[1] = 4n

let iter = 0
for( ; iter < 10000; iter+=2)
    if( (i[0] = BigInt(iter) ) % n )
        ++acc;
    
console.log(acc, iter);
ready
BigIntArray III
let data  = new BigInt64Array(4)
let iter = data[0] = 0n
const end  = data[1] = 10000n
const step = data[2] = 2n
let i = data[0]

let n = data[3] = 4n

let acc = 0;

for( ; iter < end; i = iter+=step)
      if( i % n )
          ++acc;
      
console.log(acc, iter)
ready
Brython
let i = {type: "int", value: 0}
let iter = {type: "int", value: 0}
const end = {type: "int", value: 10000}
const step = {type: "int", value: 2}
const mod = {type: "int", value: 4}

let acc= 0;
for( ; __lesser__(i, end); iter = __impl_add__(i, step) )
    if( __mod__(iter, mod) )
        ++acc;
        

console.log(acc,i)
ready

Revisions

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