asmjs

JavaScript performance comparison

Revision 4 of this test case created by Calvin Metcalf

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var colors=new Uint32Array([4281282495,4281283263,4281283775,4281284287,4281285055,4281285567,4281286335,4281286847,4281287359,4281288127,4281288639,4281289407,4281289919,4281290431,4281291199,4281291711,4281292479,4281292991,4281293503,4281294271,4281294783,4281295551,4281296063,4281296575,4281297343,4281297855,4281298367,4281299135,4281299647,4281300415,4281300927,4281301439,4281302207,4281302719,4281303487,4281303999,4281304511,4281305279,4281305791,4281306559,4281307071,4281307583,4281308351,4281308863,4281309631,4281310143,4281310655,4281311423,4281311935,4281312447,4281313215,4281313727,4281314495,4281315007,4281315519,4281316287,4281316799,4281317567,4281318079,4281318591,4281319359,4281319356,4281319354,4281319352,4281319349,4281319347,4281319344,4281319342,4281319340,4281319337,4281319335,4281319332,4281319330,4281319328,4281319325,4281319323,4281319321,4281319318,4281319316,4281319313,4281319311,4281319309,4281319306,4281319304,4281319301,4281319299,4281319297,4281319294,4281319292,4281319289,4281319287,4281319285,4281319282,4281319280,4281319277,4281319275,4281319273,4281319270,4281319268,4281319266,4281319263,4281319261,4281319258,4281319256,4281319254,4281319251,4281319249,4281319246,4281319244,4281319242,4281319239,4281319237,4281319234,4281319232,4281319230,4281319227,4281319225,4281319222,4281319220,4281319218,4281319215,4281515823,4281646895,4281777967,4281974575,4282105647,4282302255,4282433327,4282564399,4282761007,4282892079,4283088687,4283219759,4283350831,4283547439,4283678511,4283875119,4284006191,4284137263,4284333871,4284464943,4284661551,4284792623,4284923695,4285120303,4285251375,4285382447,4285579055,4285710127,4285906735,4286037807,4286168879,4286365487,4286496559,4286693167,4286824239,4286955311,4287151919,4287282991,4287479599,4287610671,4287741743,4287938351,4288069423,4288266031,4288397103,4288528175,4288724783,4288855855,4288986927,4289183535,4289314607,4289511215,4289642287,4289773359,4289969967,4290101039,4290297647,4290428719,4290559791,4290756399,4290755631,4290755119,4290754607,4290753839,4290753327,4290752559,4290752047,4290751535,4290750767,4290750255,4290749487,4290748975,4290748463,4290747695,4290747183,4290746671,4290745903,4290745391,4290744623,4290744111,4290743599,4290742831,4290742319,4290741551,4290741039,4290740527,4290739759,4290739247,4290738479,4290737967,4290737455,4290736687,4290736175,4290735407,4290734895,4290734383,4290733615,4290733103,4290732591,4290731823,4290731311,4290730543,4290730031,4290729519,4290728751,4290728239,4290727471,4290726959,4290726447,4290725679,4290725167,4290724399,4290723887,4290723375,4290722607,4290722095,4290721327,4290720815,4290720303,4290719535,4290719538,4290719540,4290719542,4290719545,4290719547,4290719550,4290719552,4290719554,4290719557,4290719559,4290719562,4290719564,4290719566,4290719569,4290719571,4290719574,4290719576,4290719578,4290719581,4290719583,4290719586,4290719588,4290719590,4290719593,4290719595,4290719597,4290719600,4290719602,4290719605,4290719607,4290719609,4290719612,4290719614,4290719617,4290719619,4290719621,4290719624,4290719626,4290719629,4290719631,4290719633,4290719636,4290719638,4290719641,4290719643,4290719645,4290719648,4290719650,4290719652,4290719655,4290719657,4290719660,4290719662,4290719664,4290719667,4290719669,4290719672,4290719674,4290719676,4290719679,4290523071,4290391999,4290260927,4290064319,4289933247,4289736639,4289605567,4289474495,4289277887,4289146815,4288950207,4288819135,4288688063,4288491455,4288360383,4288229311,4288032703,4287901631,4287705023,4287573951,4287442879,4287246271,4287115199,4286918591,4286787519,4286656447,4286459839,4286328767,4286132159,4286001087,4285870015,4285673407,4285542335,4285345727,4285214655,4285083583,4284886975,4284755903,4284624831,4284428223,4284297151,4284100543,4283969471,4283838399,4283641791,4283510719,4283314111,4283183039,4283051967,4282855359,4282724287,4282527679,4282396607,4282265535,4282068927,4281937855,4281741247,4281610175,4281479103,4290719679]);
   
    var datum = {x:649,y:359,z:11,tileID:"649:359:11",workerID:0,cr:-0.74543,ci:0.11301,maxIter:500,type:"mandlebrot"}
    var asm = new Function("stdlib", " \"use asm\";\n var pow = stdlib.Math.pow;\n\n function mandlebrot(cx, cy, maxIter) {\n    cx = +cx;\n     cy = +cy;\n     maxIter = maxIter|0;\n     var iter=0;\n     var xn= 0.0;\n     var x = 0.0;\n     var y = 0.0;\n     while ( ((pow(x,2.0) + pow(y,2.0)) < 4.0)&((iter|0) < (maxIter|0))) {\n         xn = +( pow(x,2.0) - pow(y,2.0) + cx);\n         y = +((x*y)*2.0 + cy);\n         x = +xn;\n         iter=(iter+1)|0;\n     }\n     \n     return iter|0;\n }\n return {\n mandlebrot: mandlebrot\n};");
   
    var noasm =new Function("stdlib", " var pow = stdlib.Math.pow;\n\n function mandlebrot(cx, cy, maxIter) {\n    cx = +cx;\n     cy = +cy;\n     maxIter = maxIter|0;\n     var iter=0;\n     var xn= 0.0;\n     var x = 0.0;\n     var y = 0.0;\n     while ( ((pow(x,2.0) + pow(y,2.0)) < 4.0)&((iter|0) < (maxIter|0))) {\n         xn = +( pow(x,2.0) - pow(y,2.0) + cx);\n         y = +((x*y)*2.0 + cy);\n         x = +xn;\n         iter=(iter+1)|0;\n     }\n     \n     return iter|0;\n }\n return {\n mandlebrot: mandlebrot\n};");
    var withasm=asm(window);
    var withoutasm=noasm(window);
    var tile = function(data,which) {
        var scale = Math.pow(2, data.z - 1);
        var x0 = data.x / scale - 1;
        var y0 = data.y / scale - 1;
        var d = 1/(scale<<8);
        var pixels = new Array(65536);
        var MAX_ITER=data.maxIter;
        var c,cx,cy,iter,i=0,px,py,a1,a2,a3,a4;
       
        while (i < 65536) {
            px = i%256;
            py = (i-px)>>8;
            cx = x0 + px*d;
            cy = y0 + py*d;    
            iter = which[data.type](cx, cy, MAX_ITER, data.cr, data.ci);
            c = ~~((iter/MAX_ITER)*360);
            pixels[i++] = colors[c];
            pixels[i++] = colors[c];
        }
        i=1;
        while (i < 65536) {
            px = i%256;
            py = (i-px)>>8;
            cx = x0 + px*d;
            cy = y0 + py*d;
            if(!px||!py||!px%255||py%255){
                iter = which[data.type](cx, cy, MAX_ITER, data.cr, data.ci);
                c = ~~((iter/MAX_ITER)*360);
                pixels[i++] = colors[c];
            }
            else{
                    a1=pixels[i+1];
                    a2=pixels[i-1];
                    a3=pixels[i+256];
                    a4=pixels[i-256];
                    if(a1===a2&&a2===a3&&a3===a4){
                        i++;
                    }else{
                        iter = which[data.type](cx, cy, MAX_ITER, data.cr, data.ci);
                        c = ~~((iter/MAX_ITER)*360);
                        pixels[i++] = colors[c];          
                    }
                }
            i++;
        }
        var array = new Uint32Array(pixels);
        data.pixels = array.buffer;
    };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Regular
tile(datum,withoutasm)
pending…
asm
tile(datum,withasm)
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment