array literal with push versus constructor and assignment

JavaScript performance comparison

Test case created by inst

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var constuctorWithAssignment = function () {
        var r = Math.random,
            o = new Array(64);
        for (var i = 0; i < 64; i++) {
            o[i] = String.fromCharCode(r() * 2 | 0 ? r() * 10 | 48 : r() * 26 | (r() * 2 | 0 ? 65 : 97));
        }
        return o.join('');
    },
    literalWithPush = function () {
        var r = Math.random,
            o = [];
        for (var i = 0; i < 64; i++) {
            o.push(String.fromCharCode(r() * 2 | 0 ? r() * 10 | 48 : r() * 26 | (r() * 2 | 0 ? 65 : 97)));
        }
        return o.join('');
    };
};
</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
constuctorWithAssignment
constuctorWithAssignment();
pending…
literalWithPush
literalWithPush ();
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