for loop wasm vs js

Benchmark created on


Setup

/*
int
for_loop(double c, int n) {
    double z = 0;
    for (int k = 0; k < n; k++) {
        if (z*z > 4)
            return 0;
        z = z*z + c;
    }
    return 1;
}
*/
const wasm_bin = Uint8Array.from(
[0,97,115,109,1,0,0,0,1,7,1,96,2,124,127,
1,127,3,2,1,0,5,3,1,0,2,6,8,1,127,1,65,
128,136,4,11,7,21,2,6,109,101,109,111,114,
121,2,0,8,102,111,114,95,108,111,111,112,
0,0,10,86,1,84,3,1,127,1,124,1,127,65,1,
33,2,2,64,32,1,65,1,72,13,0,68,0,0,0,0,0,
0,0,0,33,3,65,1,33,4,3,64,32,4,32,1,78,34,
2,13,1,32,4,65,1,106,33,4,32,3,32,3,162,
32,0,160,34,3,32,3,162,68,0,0,0,0,0,0,16,
64,100,69,13,0,11,11,32,2,11,0,38,4,110,
97,109,101,1,11,1,0,8,102,111,114,95,108,
111,111,112,7,18,1,0,15,95,95,115,116,97,
99,107,95,112,111,105,110,116,101,114,0,
45,9,112,114,111,100,117,99,101,114,115,1,
12,112,114,111,99,101,115,115,101,100,45,
98,121,1,12,85,98,117,110,116,117,32,99,
108,97,110,103,6,49,52,46,48,46,54]
);

const wasm_module = new WebAssembly.Module(wasm_bin);

const wasm_instance = new WebAssembly.Instance(wasm_module);

const for_loop_wasm = wasm_instance.exports.for_loop;

function for_loop(c, n) {
    let z = 0;
    for (let k = 0; k < n; k++) {
        if (z*z > 4)
            return 0;
        z = z*z + c;
    }
    return 1;
}


Test runner

Ready to run.

Testing in
TestOps/sec
wasm
for_loop_wasm(0.25, 1000)
ready
js
for_loop(0.25, 1000)
ready

Revisions

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