test

JavaScript performance comparison

Revision 48 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var o = {1:1, 2:2};
    var n = 0;
    var s = 'string';
    var arr = new Array(1000);
   
    function a(array, number){
        var narr = [];
   
        while(array.length > number){
            narr.unshift(array.slice(array.length - number));
            array.length -= number;
        }
       
        narr.unshift(array);
        return narr;
    }
   
    function b(array, chunkSize) {
        return [].concat.apply([],
            array.map(function(elem,i) {
                return i%chunkSize ? [] : [array.slice(i,i+chunkSize)];
            })
        );
    }
   
    function c(array, number){
        var narr = [];
        var start = 0;
       
        while(start < array.length){
            narr.push(array.slice(start, start + number));
            start += number;
        }
       
        return narr;
    }
};
</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
1
a(arr, 23);
pending…
2
b(arr, 23);
pending…
c(arr, 23);
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