array vs object property

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  var arr = [
            {
              "Country": "Afghanistan",
              "Full Name": "Stone Greenfelder",
              "Id": '0',
              "Email": "Candido.Schmeler@orrin.com",
              "Created At": "2006-01-10T20:33:21.729Z"
            },
            {
              "Country": "Peru",
              "Full Name": "Ernesto Eichmann",
              "Id": '1',
              "Email": "Shaina@carissa.info",
              "Created At": "2011-02-08T01:23:46.966Z"
            },
            {
              "Country": "Iceland",
              "Full Name": "Lafayette Bayer",
              "Id": '2',
              "Email": "Frank@quinton.org",
              "Created At": "1984-06-22T07:40:33.529Z"
            },
            {
              "Country": "Neutral Zone",
              "Full Name": "Angela Heidenreich",
              "Id": '3',
              "Email": "Prince@kasandra.name",
              "Created At": "2002-09-06T17:55:38.718Z"
            },
            {
              "Country": "Dronning Maud Land",
              "Full Name": "Mossie Stark",
              "Id": '4',
              "Email": "Ludwig@prudence.us",
              "Created At": "1991-02-15T20:50:25.029Z"
            },
            {
              "Country": "Pakistan",
              "Full Name": "Pinkie Harvey",
              "Id": '5',
              "Email": "Kareem@kenyatta.biz",
              "Created At": "1989-04-19T07:35:19.749Z"
            },
            {
              "Country": "Bosnia and Herzegovina",
              "Full Name": "Ayana Lesch",
              "Id": '6',
              "Email": "Caleigh@rolando.co.uk",
              "Created At": "1983-11-14T19:24:32.459Z"
            },
            {
              "Country": "Bahamas",
              "Full Name": "Carleton Gleason II",
              "Id": '7',
              "Email": "Horace@chloe.info",
              "Created At": "1986-03-18T12:14:13.730Z"
            },
            {
              "Country": "Uruguay",
              "Full Name": "Lexi Murray",
              "Id": '8',
              "Email": "Angus@ivory.us",
              "Created At": "1996-05-19T15:42:36.153Z"
            },
            {
              "Country": "Jamaica",
              "Full Name": "Dena Jast",
              "Id": '9',
              "Email": "Elyssa@naomie.me",
              "Created At": "2002-09-01T20:55:47.101Z"
            },
            {
              "Country": "Canton and Enderbury Islands",
              "Full Name": "Lenna Conn",
              "Id": '10',
              "Email": "Dangelo.Sporer@bruce.net",
              "Created At": "1983-11-29T18:22:08.533Z"
            },
            {
              "Country": "United Arab Emirates",
              "Full Name": "Miles Harris",
              "Id": '11',
              "Email": "Magdalen.Spinka@mathilde.name",
              "Created At": "1985-10-13T23:09:06.238Z"
            },
            {
              "Country": "Malaysia",
              "Full Name": "Katlynn Buckridge",
              "Id": '12',
              "Email": "Vergie@darren.us",
              "Created At": "2011-07-19T21:09:16.111Z"
            },
            {
              "Country": "Neutral Zone",
              "Full Name": "Geoffrey Schmitt",
              "Id": '13',
              "Email": "Milan@armando.org",
              "Created At": "2011-07-21T07:27:11.270Z"
            },
            {
              "Country": "Ukraine",
              "Full Name": "Floyd Heaney",
              "Id": '14',
              "Email": "Ulices_Rodriguez@amira.net",
              "Created At": "2011-12-24T04:04:16.045Z"
            },
            {
              "Country": "Chile",
              "Full Name": "Ms. Vella Kulas",
              "Id": '15',
              "Email": "Elmira.Gerlach@jamar.ca",
              "Created At": "2004-04-04T22:06:07.462Z"
            },
            {
              "Country": "Kiribati",
              "Full Name": "Freddie Hand II",
              "Id": '16',
              "Email": "Leonard@noble.me",
              "Created At": "1994-06-06T07:41:26.559Z"
            },
            {
              "Country": "Myanmar [Burma]",
              "Full Name": "Shyanne Jacobi",
              "Id": '17',
              "Email": "Violette@erika.org",
              "Created At": "1992-08-31T12:14:43.215Z"
            },
            {
              "Country": "Germany",
              "Full Name": "Ernestine Torp",
              "Id": '18',
              "Email": "Laura@tyrese.net",
              "Created At": "1984-12-12T10:08:43.262Z"
            },
            {
              "Country": "Jersey",
              "Full Name": "Pauline Wyman DDS",
              "Id": '19',
              "Email": "Candace@uriah.biz",
              "Created At": "1982-04-11T13:38:50.016Z"
            },
            {
              "Country": "Peru",
              "Full Name": "Jonas Klein PhD",
              "Id": '20',
              "Email": "Muriel.Bode@oda.ca",
              "Created At": "1980-11-26T02:35:20.451Z"
            },
            {
              "Country": "Guam",
              "Full Name": "Constantin Kertzmann",
              "Id": '21',
              "Email": "Chanel@joana.io",
              "Created At": "2006-05-24T18:53:58.803Z"
            },
            {
              "Country": "Panama",
              "Full Name": "Annamarie Cronin",
              "Id": '22',
              "Email": "Terrance.Greenholt@jorge.io",
              "Created At": "2007-07-14T16:14:00.022Z"
            },
            {
              "Country": "Taiwan",
              "Full Name": "Tracy Schroeder",
              "Id": '23',
              "Email": "Abraham@marilou.info",
              "Created At": "1984-04-27T18:58:27.955Z"
            },
            {
              "Country": "Tajikistan",
              "Full Name": "Mr. Vernice Krajcik",
              "Id": '24',
              "Email": "Hellen@genesis.ca",
              "Created At": "1981-09-12T04:48:35.996Z"
            },
            {
              "Country": "Austria",
              "Full Name": "Miss Paris Romaguera",
              "Id": '25',
              "Email": "Edgardo@cecile.biz",
              "Created At": "1981-01-25T11:44:28.325Z"
            },
            {
              "Country": "Paraguay",
              "Full Name": "Brennan Hoppe",
              "Id": '26',
              "Email": "Sherman_OReilly@scot.us",
              "Created At": "1997-02-16T11:00:33.387Z"
            },
            {
              "Country": "Saint Helena",
              "Full Name": "Jordane Schroeder",
              "Id": '27',
              "Email": "Mervin@tracy.us",
              "Created At": "1981-09-22T16:11:41.486Z"
            },
            {
              "Country": "Tunisia",
              "Full Name": "Gertrude McKenzie",
              "Id": '28',
              "Email": "Paul@lisette.com",
              "Created At": "2005-10-07T00:47:38.547Z"
            },
            {
              "Country": "Maldives",
              "Full Name": "Wilburn Deckow",
              "Id": '29',
              "Email": "Marie_Ankunding@kraig.name",
              "Created At": "1995-12-18T05:27:58.643Z"
            }
          ]
  
  var obj = { '0': 
     { Country: 'Afghanistan',
       'Full Name': 'Stone Greenfelder',
       Id: '0',
       Email: 'Candido.Schmeler@orrin.com',
       'Created At': '2006-01-10T20:33:21.729Z' },
    '1': 
     { Country: 'Peru',
       'Full Name': 'Ernesto Eichmann',
       Id: '1',
       Email: 'Shaina@carissa.info',
       'Created At': '2011-02-08T01:23:46.966Z' },
    '2': 
     { Country: 'Iceland',
       'Full Name': 'Lafayette Bayer',
       Id: '2',
       Email: 'Frank@quinton.org',
       'Created At': '1984-06-22T07:40:33.529Z' },
    '3': 
     { Country: 'Neutral Zone',
       'Full Name': 'Angela Heidenreich',
       Id: '3',
       Email: 'Prince@kasandra.name',
       'Created At': '2002-09-06T17:55:38.718Z' },
    '4': 
     { Country: 'Dronning Maud Land',
       'Full Name': 'Mossie Stark',
       Id: '4',
       Email: 'Ludwig@prudence.us',
       'Created At': '1991-02-15T20:50:25.029Z' },
    '5': 
     { Country: 'Pakistan',
       'Full Name': 'Pinkie Harvey',
       Id: '5',
       Email: 'Kareem@kenyatta.biz',
       'Created At': '1989-04-19T07:35:19.749Z' },
    '6': 
     { Country: 'Bosnia and Herzegovina',
       'Full Name': 'Ayana Lesch',
       Id: '6',
       Email: 'Caleigh@rolando.co.uk',
       'Created At': '1983-11-14T19:24:32.459Z' },
    '7': 
     { Country: 'Bahamas',
       'Full Name': 'Carleton Gleason II',
       Id: '7',
       Email: 'Horace@chloe.info',
       'Created At': '1986-03-18T12:14:13.730Z' },
    '8': 
     { Country: 'Uruguay',
       'Full Name': 'Lexi Murray',
       Id: '8',
       Email: 'Angus@ivory.us',
       'Created At': '1996-05-19T15:42:36.153Z' },
    '9': 
     { Country: 'Jamaica',
       'Full Name': 'Dena Jast',
       Id: '9',
       Email: 'Elyssa@naomie.me',
       'Created At': '2002-09-01T20:55:47.101Z' },
    '10': 
     { Country: 'Canton and Enderbury Islands',
       'Full Name': 'Lenna Conn',
       Id: '10',
       Email: 'Dangelo.Sporer@bruce.net',
       'Created At': '1983-11-29T18:22:08.533Z' },
    '11': 
     { Country: 'United Arab Emirates',
       'Full Name': 'Miles Harris',
       Id: '11',
       Email: 'Magdalen.Spinka@mathilde.name',
       'Created At': '1985-10-13T23:09:06.238Z' },
    '12': 
     { Country: 'Malaysia',
       'Full Name': 'Katlynn Buckridge',
       Id: '12',
       Email: 'Vergie@darren.us',
       'Created At': '2011-07-19T21:09:16.111Z' },
    '13': 
     { Country: 'Neutral Zone',
       'Full Name': 'Geoffrey Schmitt',
       Id: '13',
       Email: 'Milan@armando.org',
       'Created At': '2011-07-21T07:27:11.270Z' },
    '14': 
     { Country: 'Ukraine',
       'Full Name': 'Floyd Heaney',
       Id: '14',
       Email: 'Ulices_Rodriguez@amira.net',
       'Created At': '2011-12-24T04:04:16.045Z' },
    '15': 
     { Country: 'Chile',
       'Full Name': 'Ms. Vella Kulas',
       Id: '15',
       Email: 'Elmira.Gerlach@jamar.ca',
       'Created At': '2004-04-04T22:06:07.462Z' },
    '16': 
     { Country: 'Kiribati',
       'Full Name': 'Freddie Hand II',
       Id: '16',
       Email: 'Leonard@noble.me',
       'Created At': '1994-06-06T07:41:26.559Z' },
    '17': 
     { Country: 'Myanmar [Burma]',
       'Full Name': 'Shyanne Jacobi',
       Id: '17',
       Email: 'Violette@erika.org',
       'Created At': '1992-08-31T12:14:43.215Z' },
    '18': 
     { Country: 'Germany',
       'Full Name': 'Ernestine Torp',
       Id: '18',
       Email: 'Laura@tyrese.net',
       'Created At': '1984-12-12T10:08:43.262Z' },
    '19': 
     { Country: 'Jersey',
       'Full Name': 'Pauline Wyman DDS',
       Id: '19',
       Email: 'Candace@uriah.biz',
       'Created At': '1982-04-11T13:38:50.016Z' },
    '20': 
     { Country: 'Peru',
       'Full Name': 'Jonas Klein PhD',
       Id: '20',
       Email: 'Muriel.Bode@oda.ca',
       'Created At': '1980-11-26T02:35:20.451Z' },
    '21': 
     { Country: 'Guam',
       'Full Name': 'Constantin Kertzmann',
       Id: '21',
       Email: 'Chanel@joana.io',
       'Created At': '2006-05-24T18:53:58.803Z' },
    '22': 
     { Country: 'Panama',
       'Full Name': 'Annamarie Cronin',
       Id: '22',
       Email: 'Terrance.Greenholt@jorge.io',
       'Created At': '2007-07-14T16:14:00.022Z' },
    '23': 
     { Country: 'Taiwan',
       'Full Name': 'Tracy Schroeder',
       Id: '23',
       Email: 'Abraham@marilou.info',
       'Created At': '1984-04-27T18:58:27.955Z' },
    '24': 
     { Country: 'Tajikistan',
       'Full Name': 'Mr. Vernice Krajcik',
       Id: '24',
       Email: 'Hellen@genesis.ca',
       'Created At': '1981-09-12T04:48:35.996Z' },
    '25': 
     { Country: 'Austria',
       'Full Name': 'Miss Paris Romaguera',
       Id: '25',
       Email: 'Edgardo@cecile.biz',
       'Created At': '1981-01-25T11:44:28.325Z' },
    '26': 
     { Country: 'Paraguay',
       'Full Name': 'Brennan Hoppe',
       Id: '26',
       Email: 'Sherman_OReilly@scot.us',
       'Created At': '1997-02-16T11:00:33.387Z' },
    '27': 
     { Country: 'Saint Helena',
       'Full Name': 'Jordane Schroeder',
       Id: '27',
       Email: 'Mervin@tracy.us',
       'Created At': '1981-09-22T16:11:41.486Z' },
    '28': 
     { Country: 'Tunisia',
       'Full Name': 'Gertrude McKenzie',
       Id: '28',
       Email: 'Paul@lisette.com',
       'Created At': '2005-10-07T00:47:38.547Z' },
    '29': 
     { Country: 'Maldives',
       'Full Name': 'Wilburn Deckow',
       Id: '29',
       Email: 'Marie_Ankunding@kraig.name',
       'Created At': '1995-12-18T05:27:58.643Z' } }
  
  
  arrayFromObj = [];
  function objToArray(o){
    var array = [];
    for (var key in o) {
      var value = o[key];
      array.push(value);
    }
    return array;
  }

};
</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
retrieving value object
o = obj['27']
pending…
retrieving value array
a = _.find(arr, { 'Id': '27' });
pending…
array by index
a = arr[27]
pending…
object to array
arrayFromObj = objToArray(obj);
pending…
object to array _.every
array = _.every(obj)
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