Test 2qw

JavaScript performance comparison

Test case created by Tam Huynh

Preparation code

<script type="text/javascript" src="http://sns.sgcharo.com/static/common/js/mobion.core.js"></script>
<div id="mainDiv"></div>
<script>
Benchmark.prototype.setup = function() {
    var numEles = 10000;
    var idx = {};
    function generateElements(){
        var d = document.getElementById("mainDiv");
        var str = [];
        for(var i=0;i<numEles;i++){
        str.push("<div id='d_" + i + "' class='dataTest' >" + i + "</div>");
        }
        d.innerHTML = str.join('');
        }
    generateElements();
   
    function selectElementsById(){
    var eles = [];
    for(var i=0;i<numEles;i++){
    var id = ((i * 99) % numEles);
    eles.push(document.getElementById("d_1" + id));
    }
    console.log(eles);
    }
   
    function selectElementsWithIndex(){
    var eles = [];
    mb("div.dataTest").each(function() {
    eles.push(this);
    });
    console.log(eles);
    }
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
getelementbyid
//Test getElementById
var x = selectElementsById();
pending…
getelementbytagname
var x = selectElementsWithIndex();
pending…

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

Compare results of other browsers

0 comments

Add a comment