Initialise array with zeros

JavaScript performance comparison

Revision 6 of this test case created

Info

Create an array of predefined length filled entirely with zeros.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    // Final array will be 1,000,000 elements long
   
    var zeros = getZeros(),
        total_zeros = 1e6,
        i = total_zeros - zeros.length;
   
    function getZeros() {
        var i = Math.ceil(Math.random() * 1000),
            zs = [];
        while (i--) zs.push(0);
        return zs
    }
};
</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
Push
while (i--) zeros.push(0);
pending…
Index
while (--i) zeros[i] = 0;
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