Array.push vs Array[Array.length] (v2)

Revision 2 of this benchmark created by Jonas Finnemann Jensen on


Setup

var results = [];
  var objects = {'user:3:profile': 
     { id: 3,
       user_id: 3,
       gender: 'male',
       birthdate: '1978-4-26',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1348659760,
       photo_id: 1386,
       description_id: 20 },
    'user:4:profile': 
     { id: 4,
       user_id: 4,
       gender: 'male',
       birthdate: '1990-1-7',
       city: 'Frederiksberg',
       country_id: 58,
       active: 1,
       visible: 0,
       timestamp: 1351107792,
       photo_id: 363,
       description_id: 24 },
    'user:5:profile': 
     { id: 5,
       user_id: 5,
       gender: 'male',
       birthdate: '1988-7-14',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1344585658,
       photo_id: 38,
       description_id: 137 },
    'user:6:profile': 
     { id: 6,
       user_id: 6,
       gender: 'male',
       birthdate: '1989-11-7',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1344605331,
       photo_id: 242,
       description_id: 23 },
    'user:7:profile': 
     { id: 7,
       user_id: 7,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1344625770,
       photo_id: 0,
       description_id: 0 },
    'user:8:profile': 
     { id: 8,
       user_id: 8,
       gender: 'male',
       birthdate: '1980-5-13',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1344841100,
       photo_id: 1106,
       description_id: 31 },
    'user:9:profile': 
     { id: 9,
       user_id: 9,
       gender: 'male',
       birthdate: '1977-11-27',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1344841147,
       photo_id: 892,
       description_id: 51 },
    'user:10:profile': 
     { id: 10,
       user_id: 10,
       gender: 'female',
       birthdate: '1985-12-18',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1344849968,
       photo_id: 1040,
       description_id: 43 },
    'user:11:profile': 
     { id: 11,
       user_id: 11,
       gender: 'female',
       birthdate: '1986-9-6',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1347631461,
       photo_id: 1046,
       description_id: 198 },
    'user:12:profile': 
     { id: 12,
       user_id: 12,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1348227416,
       photo_id: 0,
       description_id: 0 },
    'user:13:profile': 
     { id: 13,
       user_id: 13,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1348227915,
       photo_id: 0,
       description_id: 0 },
    'user:14:profile': 
     { id: 14,
       user_id: 14,
       gender: '',
       birthdate: '-1-1--1',
       city: '',
       country_id: -1,
       active: 1,
       visible: 1,
       timestamp: 1348476711,
       photo_id: 1100,
       description_id: 208 },
    'user:15:profile': 
     { id: 15,
       user_id: 15,
       gender: 'female',
       birthdate: '1990-2-2',
       city: 'Kolding',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1348668256,
       photo_id: 1072,
       description_id: 199 },
    'user:16:profile': 
     { id: 16,
       user_id: 16,
       gender: 'female',
       birthdate: '-1--1--1',
       city: '',
       country_id: -1,
       active: 1,
       visible: 1,
       timestamp: 1348668475,
       photo_id: 1075,
       description_id: 200 },
    'user:17:profile': 
     { id: 17,
       user_id: 17,
       gender: 'male',
       birthdate: '1990--1--1',
       city: '',
       country_id: -1,
       active: 1,
       visible: 1,
       timestamp: 1348668585,
       photo_id: 1078,
       description_id: 201 },
    'user:18:profile': 
     { id: 18,
       user_id: 18,
       gender: 'male',
       birthdate: '1989-1-5',
       city: '',
       country_id: -1,
       active: 1,
       visible: 1,
       timestamp: 1348668786,
       photo_id: 1161,
       description_id: 202 },
    'user:19:profile': 
     { id: 19,
       user_id: 19,
       gender: 'male',
       birthdate: '1992-7-3',
       city: '',
       country_id: -1,
       active: 1,
       visible: 1,
       timestamp: 1348668892,
       photo_id: 1084,
       description_id: 203 },
    'user:20:profile': 
     { id: 20,
       user_id: 20,
       gender: 'male',
       birthdate: '1988-2-17',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1349167899,
       photo_id: 1280,
       description_id: 320 },
    'user:21:profile': 
     { id: 21,
       user_id: 21,
       gender: '',
       birthdate: '-1--1--1',
       city: '',
       country_id: -1,
       active: 1,
       visible: 1,
       timestamp: 1350037038,
       photo_id: 1234,
       description_id: 297 },
    'user:22:profile': 
     { id: 22,
       user_id: 22,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350391447,
       photo_id: 0,
       description_id: 0 },
    'user:23:profile': 
     { id: 23,
       user_id: 23,
       gender: 'female',
       birthdate: '-1-1-1',
       city: '',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1350392243,
       photo_id: 1501,
       description_id: 339 },
    'user:24:profile': 
     { id: 24,
       user_id: 24,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350458961,
       photo_id: 0,
       description_id: 0 },
    'user:25:profile': 
     { id: 25,
       user_id: 25,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350465175,
       photo_id: 0,
       description_id: 0 },
    'user:26:profile': 
     { id: 26,
       user_id: 26,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 0,
       visible: 1,
       timestamp: 1350896031,
       photo_id: 1392,
       description_id: 0 },
    'user:27:profile': 
     { id: 27,
       user_id: 27,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350655914,
       photo_id: 0,
       description_id: 0 },
    'user:29:profile': 
     { id: 29,
       user_id: 29,
       gender: 'male',
       birthdate: '1953-5-1',
       city: 'Vejle',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1350728353,
       photo_id: 0,
       description_id: 398 },
    'user:30:profile': 
     { id: 30,
       user_id: 30,
       gender: 'male',
       birthdate: '1985-8-11',
       city: 'Copenhagen',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1350728839,
       photo_id: 1376,
       description_id: 395 },
    'user:31:profile': 
     { id: 31,
       user_id: 31,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350764960,
       photo_id: 0,
       description_id: 0 },
    'user:32:profile': 
     { id: 32,
       user_id: 32,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350829282,
       photo_id: 0,
       description_id: 0 },
    'user:33:profile': 
     { id: 33,
       user_id: 33,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350848756,
       photo_id: 0,
       description_id: 0 },
    'user:34:profile': 
     { id: 34,
       user_id: 34,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350854776,
       photo_id: 0,
       description_id: 0 },
    'user:35:profile': 
     { id: 35,
       user_id: 35,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1350897616,
       photo_id: 0,
       description_id: 0 },
    'user:36:profile': 
     { id: 36,
       user_id: 36,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351001443,
       photo_id: 0,
       description_id: 0 },
    'user:37:profile': 
     { id: 37,
       user_id: 37,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351003467,
       photo_id: 0,
       description_id: 0 },
    'user:38:profile': 
     { id: 38,
       user_id: 38,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351007408,
       photo_id: 0,
       description_id: 0 },
    'user:39:profile': 
     { id: 39,
       user_id: 39,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351009061,
       photo_id: 0,
       description_id: 0 },
    'user:40:profile': 
     { id: 40,
       user_id: 40,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351028417,
       photo_id: 0,
       description_id: 0 },
    'user:41:profile': 
     { id: 41,
       user_id: 41,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351078973,
       photo_id: 0,
       description_id: 0 },
    'user:42:profile': 
     { id: 42,
       user_id: 42,
       gender: 'male',
       birthdate: '1988--1--1',
       city: 'Aarhus',
       country_id: 58,
       active: 1,
       visible: 1,
       timestamp: 1351158079,
       photo_id: 1517,
       description_id: 472 },
    'user:43:profile': 
     { id: 43,
       user_id: 43,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351435401,
       photo_id: 0,
       description_id: 0 },
    'user:44:profile': 
     { id: 44,
       user_id: 44,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351608461,
       photo_id: 0,
       description_id: 0 },
    'user:45:profile': 
     { id: 45,
       user_id: 45,
       gender: '',
       birthdate: '',
       city: '',
       country_id: 0,
       active: 1,
       visible: 1,
       timestamp: 1351670642,
       photo_id: 0,
       description_id: 0 } }

Test runner

Ready to run.

Testing in
TestOps/sec
Array.push
var res = [];
for (var key in objects) {
  res.push(objects[key]);
}
ready
Array.length
var res = [];
for (var key in objects) {
  res[res.length] = objects[key];
}
ready
Array[i++]
var res = [], i = 0;
for (var key in objects) {
  res[i++] = objects[key];
}
ready

Revisions

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