Object VS Array VS "Native Linked List"

JavaScript performance comparison

Revision 8 of this test case created by

Preparation code

<script src="https://pic-o.com/wp-content/uploads/2011/12/jsCompatible.js">
</script>
<script src="https://pic-o.com/wp-content/uploads/2011/12/jsClass.js">
</script>
<script src="https://pic-o.com/wp-content/uploads/2011/12/divLinkedList.js">
</script>
<script>
  Benchmark.prototype.setup = function() {
    //Base variable creation testing
    var read;
    
    var zero = 0;
    var blankObj = {};
    var blankArr = [];
    var blankDLL = new(divLinkedList)();
    
    //Population limit for pre generated content
    var populateLimit = 1000;
    var populateMid = populateLimit / 2;
    var populateNext = populateLimit + 1;
    
    var count = 0;
    var countMid = populateMid;
    var countNext = populateNext;
    
    var objPopLimit = 'p' + populateLimit;
    var objPopMid = 'p' + populateMid;
    var objPopNext = 'p' + populateNext;
    var objPopZero = 'p' + zero;
    
    //Premade content testing
    var testObj = {};
    for (var a = 0; a <= populateLimit; a++) {
      testObj['p' + a] = a;
    }
    var testArr = [];
    for (var a = 0; a <= populateLimit; a++) {
      testArr[a] = ('p' + a);
    }
    var testDLL = new(divLinkedList)();
    for (var a = 0; a <= populateLimit; a++) {
      testDLL.push('p' + a);
    }
  };

  Benchmark.prototype.teardown = function() {
    if( !window.testDump ) {
    window.testDump = [];
    }
    
    if( Math.random() >= 0.9999 ) {
    window.testDump.push( [
        blankObj['p'+Math.round(Math.random()*1000)], 
        (blankArr.length > 0)?( blankArr[ Math.round(Math.random()*( blankArr.length-1 )) ] ) : 0, 
        (blankDLL.length > 0)?( blankDLL.gets( Math.round(Math.random()*( blankArr.length-1 )) ) ) : 0,
        testObj['p'+Math.round(Math.random()*1000)], 
        (testArr.length > 0)?( testArr[ Math.round(Math.random()*( testArr.length-1 )) ] ) : 0, 
        (testDLL.length > 0)?( testDLL.gets( Math.round(Math.random()*( testDLL.length-1 )) ) ) : 0
    ] );
    }
  };
</script>
      
<script>
Benchmark.prototype.setup = function() {
  vm.width = [
            '220',
            '220.5',
            '221',
            '221.5',
            '222',
            '222.5',
            '223',
            '223.5',
            '224',
            '224.5',
            '225',
            '225.5',
            '226',
            '226.5',
            '227',
            '227.5',
            '228',
            '228.5',
            '229',
            '229.5',
            '230',
            '230.5',
            '231',
            '231.5',
            '232',
            '232.5',
            '233',
            '233.5',
            '234',
            '234.5',
            '235',
            '235.5',
            '236',
            '236.5',
            '237',
            '237.5',
            '238',
            '238.5',
            '239',
            '239.5',
            '240',
            '240.5',
            '241',
            '241.5',
            '242',
            '242.5',
            '243',
            '243.5',
            '244',
            '244.5',
            '245',
            '245.5',
            '246',
            '246.5',
            '247',
            '247.5',
            '248',
            '248.5',
            '249',
            '249.5',
            '250',
            '250.5',
            '251',
            '251.5',
            '252',
            '252.5',
            '253',
            '253.5',
            '254',
            '254.5',
            '255',
            '255.5',
            '256',
            '256.5',
            '257',
            '257.5',
            '258',
            '258.5',
            '259',
            '259.5',
            '260',
            '260.5',
            '261',
            '261.5',
            '262',
            '262.5',
            '263',
            '263.5',
            '264',
            '264.5',
            '265',
            '265.5',
            '266',
            '266.5',
            '267',
            '267.5',
            '268',
            '268.5',
            '269',
            '269.5',
            '270',
            '270.5',
            '271',
            '271.5',
            '272',
            '272.5',
            '273',
            '273.5',
            '274',
            '274.5',
            '275',
            '275.5',
            '276',
            '276.5',
            '277',
            '277.5',
            '278',
            '278.5',
            '279',
            '279.5',
            '280',
            '280.5',
            '281',
            '281.5',
            '282',
            '282.5',
            '283',
            '283.5',
            '284',
            '284.5',
            '285',
            '285.5',
            '286',
            '286.5',
            '287',
            '287.5',
            '288',
            '288.5',
            '289',
            '289.5',
            '290',
            '290.5',
            '291',
            '291.5',
            '292',
            '292.5',
            '293',
            '293.5',
            '294',
            '294.5',
            '295',
            '295.5',
            '296',
            '296.5',
            '297',
            '297.5',
            '298',
            '298.5',
            '299',
            '299.5',
            '300',
            '300.5',
            '301',
            '301.5',
            '302',
            '302.5',
            '303',
            '303.5',
            '304',
            '304.5',
            '305',
            '305.5',
            '306',
            '306.5',
            '307',
            '307.5',
            '308',
            '308.5',
            '309',
            '309.5',
            '310',
            '310.5',
            '311',
            '311.5',
            '312',
            '312.5',
            '313',
            '313.5',
            '314',
            '314.5',
            '315',
            '315.5',
            '316',
            '316.5',
            '317',
            '317.5',
            '318',
            '318.5',
            '319',
            '319.5',
            '320',
            '320.5',
            '321',
            '321.5',
            '322',
            '322.5',
            '323',
            '323.5',
            '324',
            '324.5',
            '325',
            '325.5',
            '326',
            '326.5',
            '327',
            '327.5',
            '328',
            '328.5',
            '329',
            '329.5',
            '330',
            '330.5',
            '331',
            '331.5',
            '332',
            '332.5',
            '333',
            '333.5',
            '334',
            '334.5',
            '335',
            '335.5',
            '336',
            '336.5',
            '337',
            '337.5',
            '338',
            '338.5',
            '339',
            '339.5',
            '340',
            '340.5',
            '341',
            '341.5',
            '342',
            '342.5',
            '343',
            '343.5',
            '344',
            '344.5',
            '345',
            '345.5',
            '346',
            '346.5',
            '347',
            '347.5',
            '348',
            '348.5',
            '349',
            '349.5',
            '350',
            '350.5',
            '351',
            '351.5',
            '352',
            '352.5',
            '353',
            '353.5',
            '354',
            '354.5',
            '355',
            '355.5',
            '356',
            '356.5',
            '357',
            '357.5',
            '358',
            '358.5',
            '359',
            '359.5',
            '360',
            '360.5',
            '361',
            '361.5',
            '362',
            '362.5',
            '363',
            '363.5',
            '364',
            '364.5',
            '365',
            '365.5',
            '366',
            '366.5',
            '367',
            '367.5',
            '368',
            '368.5',
            '369',
            '369.5',
            '370',
            '370.5',
            '371',
            '371.5',
            '372',
            '372.5',
            '373',
            '373.5',
            '374',
            '374.5',
            '375',
            '375.5',
            '376',
            '376.5',
            '377',
            '377.5',
            '378',
            '378.5',
            '379',
            '379.5',
            '380',
            '380.5',
            '381',
            '381.5',
            '382',
            '382.5',
            '383',
            '383.5',
            '384',
            '384.5',
            '385',
            '385.5',
            '386',
            '386.5',
            '387',
            '387.5',
            '388',
            '388.5',
            '389',
            '389.5',
            '390',
            '390.5',
            '391',
            '391.5',
            '392',
            '392.5',
            '393',
            '393.5',
            '394',
            '394.5',
            '395',
            '395.5',
            '396',
            '396.5',
            '397',
            '397.5',
            '398',
            '398.5',
            '399',
            '399.5',
            '400',
            '400.5',
            '401',
            '401.5',
            '402',
            '402.5',
            '403',
            '403.5',
            '404',
            '404.5',
            '405',
            '405.5',
            '406',
            '406.5',
            '407',
            '407.5',
            '408',
            '408.5',
            '409',
            '409.5',
            '410',
            '410.5',
            '411',
            '411.5',
            '412',
            '412.5',
            '413',
            '413.5',
            '414',
            '414.5',
            '415',
            '415.5',
            '416',
            '416.5',
            '417',
            '417.5',
            '418',
            '418.5',
            '419',
            '419.5',
            '420',
            '420.5',
            '421',
            '421.5',
            '422',
            '422.5',
            '423',
            '423.5',
            '424',
            '424.5',
            '425',
            '425.5',
            '426',
            '426.5',
            '427',
            '427.5',
            '428',
            '428.5',
            '429',
            '429.5',
            '430',
            '430.5',
            '431',
            '431.5',
            '432',
            '432.5',
            '433',
            '433.5',
            '434',
            '434.5',
            '435',
            '435.5',
            '436',
            '436.5',
            '437',
            '437.5',
            '438',
            '438.5',
            '439',
            '439.5',
            '440',
            '440.5',
            '441',
            '441.5',
            '442',
            '442.5',
            '443',
            '443.5',
            '444',
            '444.5',
            '445',
            '445.5',
            '446',
            '446.5',
            '447',
            '447.5',
            '448',
            '448.5',
            '449',
            '449.5',
            '450',
            '450.5',
            '451',
            '451.5',
            '452',
            '452.5',
            '453',
            '453.5',
            '454',
            '454.5',
            '455',
            '455.5',
            '456',
            '456.5',
            '457',
            '457.5',
            '458',
            '458.5',
            '459',
            '459.5',
            '460'
        ];

};
</script>

Preparation code output

<script src="https://pic-o.com/wp-content/uploads/2011/12/jsClass.js"> </script> <script src="https://pic-o.com/wp-content/uploads/2011/12/divLinkedList.js"> </script> <script> Benchmark.prototype.setup = function() { //Base variable creation testing var read; var zero = 0; var blankObj = {}; var blankArr = []; var blankDLL = new(divLinkedList)(); //Population limit for pre generated content var populateLimit = 1000; var populateMid = populateLimit / 2; var populateNext = populateLimit + 1; var count = 0; var countMid = populateMid; var countNext = populateNext; var objPopLimit = 'p' + populateLimit; var objPopMid = 'p' + populateMid; var objPopNext = 'p' + populateNext; var objPopZero = 'p' + zero; //Premade content testing var testObj = {}; for (var a = 0; a <= populateLimit; a++) { testObj['p' + a] = a; } var testArr = []; for (var a = 0; a <= populateLimit; a++) { testArr[a] = ('p' + a); } var testDLL = new(divLinkedList)(); for (var a = 0; a <= populateLimit; a++) { testDLL.push('p' + a); } }; Benchmark.prototype.teardown = function() { if( !window.testDump ) { window.testDump = []; } if( Math.random() >= 0.9999 ) { window.testDump.push( [ blankObj['p'+Math.round(Math.random()*1000)], (blankArr.length > 0)?( blankArr[ Math.round(Math.random()*( blankArr.length-1 )) ] ) : 0, (blankDLL.length > 0)?( blankDLL.gets( Math.round(Math.random()*( blankArr.length-1 )) ) ) : 0, testObj['p'+Math.round(Math.random()*1000)], (testArr.length > 0)?( testArr[ Math.round(Math.random()*( testArr.length-1 )) ] ) : 0, (testDLL.length > 0)?( testDLL.gets( Math.round(Math.random()*( testDLL.length-1 )) ) ) : 0 ] ); } }; </script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Obj Create
read = {};
count++;
pending…
Obj (blank) Property Adds
blankObj['p' + count] = count;
count++;
pending…
Obj (filled) Property Adds
testObj['p' + countNext] = countNext;
countNext++;
pending…
Obj Delete Starts
delete testObj['p' + count];
count++;
pending…
Obj Null Starts
testObj['p' + count] = null;
count++;
pending…
Obj Delete Mids
delete testObj['p' + countMid];
countMid++;
pending…
Obj Null Mids
testObj['p' + countMid] = null;
countMid++;
pending…
Obj Delete Ends
countNext--;
delete testObj['p' + countNext];
pending…
Obj Null Ends
countNext--;
testObj['p' + countNext] = null;
pending…
Obj Read start
read = testObj[objPopZero];
count++;
pending…
Obj Read Mid
read = testObj[objPopMid];
count++;
pending…
Obj Read End
read = testObj[objPopLimit];
count++;
pending…
Obj Write Start
testObj[objPopZero] = count;
count++;
pending…
Obj Write Mid
testObj[objPopMid] = count;
count++;
pending…
Obj Write End
testObj[objPopLimit] = count;
count++;
pending…
Array Create
read = [];
count++;
pending…
Array (blank) Property Add
blankArr[count] = ('p' + count);
count++;
pending…
Array (filled) Property Add
testArr[countNext] = ('p' + countNext);
countNext++;
pending…
Array (blank) .push
blankArr.push(count);
count++;
pending…
Array (filled) .push
testArr.push(count);
count++;
pending…
Array (filled) .pop
testArr.pop();
count++;
pending…
Array (filled) .shift
testArr.shift();
count++;
pending…
Array (filled) .unshift
testArr.unshift(count);
count++;
pending…
Array (blank) .unshift
testArr.unshift(count);
count++;
pending…
Array (filled) .slice(start, mid)
read = testArr.slice(zero, populateMid);
count++;
pending…
Array (filled) .slice(mid, [end])
read = testArr.slice(populateMid);
count++;
pending…
Array (filled) .slice(mid, end)
read = testArr.slice(populateMid, populateNext);
count++;
pending…
Array (filled) .slice(mid, end)
read = testArr.slice(populateMid, populateLimit);
count++;
pending…
Array Delete Start
delete testArr[count];
count++;
pending…
Array Null Start
testArr[count] = null;
count++;
pending…
Array Delete Mid
delete testArr[countMid];
countMid++;
pending…
Array Null Mid
testArr[countMid] = null;
countMid++;
pending…
Array Delete End
countNext--;
delete testArr[countNext];
pending…
Array Null End
countNext--;
testArr[countNext] = null;
pending…
Array Read Start
read = testArr[zero];
count++;
pending…
Array Read Mid
read = testArr[populateMid];
count++;
pending…
Array Read End
read = testArr[populateLimit];
count++;
pending…
Array Write Start
testArr[zero] = count;
count++;
pending…
Array Write Mid
testArr[populateMid] = count;
count++;
pending…
Array Write End
testArr[populateLimit] = count;
count++;
pending…
Array Splice Mid Insert
testArr.splice(populateMid, 0, count);
count++;
pending…
Array Splice Mid Remove
//I have no idea how to fix this, to prevent out of bound
testArr.splice(populateMid, 1);
count++;
pending…
divLinkedList Create
read = new(divLinkedList)();
count++;
pending…
divLinkedList Adding (blank) .sets(0, data)
blankDLL.sets(count, count);
count++;
pending…
divLinkedList Adding (filled) .sets(populateNext, data)
blankDLL.sets(countNext, countNext);
countNext++;
pending…
divLinkedList (blank).push
blankDLL.push(count);
count++;
pending…
divLinkedList (filled).push
testDLL.push(count);
count++;
pending…
divLinkedList (filled).pop
testDLL.pop();
count++;
pending…
divLinkedList (filled).shift
testDLL.shift();
count++;
pending…
divLinkedList (filled).unshift
testDLL.unshift(count);
count++;
pending…
divLinkedList (blank).unshift
blankDLL.unshift(count);
count++;
pending…
divLinkedList Null Start
testDLL.sets(0, null);
count++;
pending…
divLinkedList Null Mid
testDLL.sets(populateMid, null);
count++;
pending…
divLinkedList Null End
testDLL.sets(populateLimit, null);
count++;
pending…
divLinkedList Null post-start
testDLL.sets(zero + 1, null);
count++;
pending…
divLinkedList Null pre-End
testDLL.sets(populateLimit - 1, null);
count++;
pending…
divLinkedList Read Start
read = testDLL.gets(zero);
count++;
pending…
divLinkedList Read Mid
read = testDLL.gets(populateMid);
count++;
pending…
divLinkedList Read End
read = testDLL.gets(populateLimit);
count++;
pending…
divLinkedList Read post-Start
read = testDLL.gets(zero + 1);
count++;
pending…
divLinkedList Read pre-End
read = testDLL.gets(populateLimit - 1);
count++;
pending…
divLinkedList Null Mid
testDLL.sets(populateMid, null);
count++;
pending…
divLinkedList Write Mid
testDLL.sets(populateMid, count);
count++;
pending…
divLinkedList Splice Mid Insert
testDLL.splice(populateMid, 0, count);
count++;
pending…
divLinkedList Splice Mid Remove
//testDLL.splice(populateMid, 1); //I have no idea how to fix this, it just ran too fast (the link list tends to runs out) and break
testDLL.splice(populateMid, 1, count);
count++;
pending…
Array splice removal
//I have no idea how to fix this, to prevent out of bound
testArr.splice(populateMid, 1);
count++;
pending…
Array splice removal add
//I have no idea how to fix this, to prevent out of bound
testArr.splice(populateMid, 1, count);
count++;
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.

0 Comments