ASM.js, is it dead? (v5)

Revision 5 of this benchmark created on


Setup

// Sane Summation
function saneSum(x) {
	
    var sum = 0;
    for (var j = 0; j < x; j++) {
        for (var i = 0; i < j; i++) {
            sum += i;
        }
    }
	return sum;
}

// Opti Summation
 function optiSum(x) {
 	x = x | 0;
    var i = 0;
    var sum = 0;
    var j = 0;
    for(j = 0; (j | 0) < (x | 0); j = (j + 1) | 0) {
        for(i = 0; (i | 0) < (j | 0); i = (i + 1) | 0) {
            sum = (sum + i) | 0;
        }
   	}
    return sum | 0;
}

// Special negation function, since js stores 32 bit integers, but we need 4/8/16 bits.
function ASMModule(stdlib, foreign, heap) {
    "use asm";

    function optiSum(x) {
        x = x | 0;
        var i = 0;
        var sum = 0;
        var j = 0;
        for(j = 0; (j | 0) < (x | 0); j = (j + 1) | 0) {
            for(i = 0; (i | 0) < (j | 0); i = (i + 1) | 0) {
                sum = (sum + i) | 0;
            }
        }
        return sum | 0;
    }

     return { optiSum: optiSum };
}

var module = ASMModule(globalThis, {}, new ArrayBuffer(4 * 1024));

Test runner

Ready to run.

Testing in
TestOps/sec
Normal, Sane Code
sum = saneSum(10000);
ready
Chad, ASM.js Code
sum = optiSum(10000);
ready
True ASM.js Code
sum = module.optiSum(10000);
ready

Revisions

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