double up solutions (v2)

Revision 2 of this benchmark created by Eric on


Setup

function doubleUp$ARRAY(arrayOfNumbers) {
        var len = arrayOfNumbers.length;
        var result = [];
        var i, tmp;
    
        for (i = 0; i < len; ++i) {
            tmp = arrayOfNumbers[i];
    
            result.push(tmp, tmp);
        }
    
        return result;
    }
    
    function doubleUp$CONCAT_SORT(data) {
        return data.concat(data).sort();
    }
    
    
    function doubleUp$REDUCE( data ) {
        return data.reduce( function(storage, val) { storage.push(val,val); return storage; }, [] );
    }
    
    function doubleUp_index_insertion( data ) {
        var i = 0;
        var l = data.length;
        var storage = [];
    
        for ( ; i < l; ++i ) {
            storage[ storage.length ] = data[i];
            storage[ storage.length ] = data[i];
        }
    
        return storage;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
simple approach
doubleUp$ARRAY([1,2,3,4,5]);

 
ready
concat sort approach
doubleUp$CONCAT_SORT([1,2,3,4,5]);
ready
Using array reduce
doubleUp$REDUCE([1,2,3,4,5]);
ready
doubleUp_index_insertion([1,2,3,4,5]);
ready

Revisions

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