isObject performance

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var smallObj = {};
  var bigObj = {
      "id": 1,
      "jsonrpc": "2.0",
      "total": 20,
      "result": [{
          "id": 1,
          "avatar": "images/user_1.png",
          "age": 12,
          "admin": true,
          "name": "Филипп Литвинов",
          "company": "Polytheon",
          "phone": "+70950696751",
          "email": "filipp@polytheon.com",
          "registerDate": "Fri, 25 Mar 2011 20:40:41 GMT",
          "friends": [{
              "id": 1,
              "name": "Степан Баранов",
              "phone": "+70950914596"
          }, {
              "id": 2,
              "name": "Ефим Марченко",
              "phone": "+70950743936"
          }, {
              "id": 3,
              "name": "Анатолий Бондаренко",
              "phone": "+70950814362"
          }],
          "field": "field value"
      }, {
          "id": 2,
          "avatar": "images/user_2.png",
          "age": -16,
          "admin": true,
          "name": "Гарри Морозов",
          "company": "Superscope",
          "phone": "+70957016691",
          "email": "garri@superscope.com",
          "registerDate": "Fri, 21 Jul 1972 14:45:15 GMT",
          "friends": [{
              "id": 1,
              "name": "Игнат Волков",
              "phone": "+70951704370"
          }, {
              "id": 2,
              "name": "Евгений Новиков",
              "phone": "+70959825662"
          }, {
              "id": 3,
              "name": "Карл Рябов",
              "phone": "+70956270792"
          }],
          "field": "field value"
      }, {
          "id": 3,
          "avatar": "images/user_3.png",
          "age": 53,
          "admin": true,
          "name": "Владимир Смирнов",
          "company": "Orthosoft",
          "phone": "+70953713267",
          "email": "vladimir@orthosoft.com",
          "registerDate": "Thu, 17 Sep 1998 04:47:11 GMT",
          "friends": [{
              "id": 1,
              "name": "Карл Рябов",
              "phone": "+70955904146"
          }, {
              "id": 2,
              "name": "Константин Павлов",
              "phone": "+70952800341"
          }, {
              "id": 3,
              "name": "Прохор Титов",
              "phone": "+70950914206"
          }],
          "field": "field value"
      }, {
          "id": 4,
          "avatar": "images/user_4.png",
          "age": 33,
          "admin": true,
          "name": "Мирон Юдин",
          "company": "Raylog",
          "phone": "+70957411818",
          "email": "miron@raylog.com",
          "registerDate": "Fri, 06 Jul 1990 14:00:06 GMT",
          "friends": [{
              "id": 1,
              "name": "Максим Степанов",
              "phone": "+70954359489"
          }, {
              "id": 2,
              "name": "Филипп Литвинов",
              "phone": "+70954457923"
          }, {
              "id": 3,
              "name": "Арсен Попов",
              "phone": "+70952379476"
          }],
          "field": "field value"
      }, {
          "id": 5,
          "avatar": "images/user_5.png",
          "age": 7,
          "admin": false,
          "name": "Эдуард Лебедев",
          "company": "Quintegrity",
          "phone": "+70956934034",
          "email": "eduard@quintegrity.com",
          "registerDate": "Fri, 22 Jun 1984 17:10:12 GMT",
          "friends": [{
              "id": 1,
              "name": "Семен Козлов",
              "phone": "+70953435026"
          }, {
              "id": 2,
              "name": "Осип Григорьев",
              "phone": "+70951238455"
          }, {
              "id": 3,
              "name": "Леонид Приходько",
              "phone": "+70957890592"
          }],
          "field": "field value"
      }, {
          "id": 6,
          "avatar": "images/user_6.png",
          "age": 33,
          "admin": false,
          "name": "Андрей Петров",
          "company": "RoboAerlogix",
          "phone": "+70957783794",
          "email": "andrey@roboaerlogix.com",
          "registerDate": "Sat, 13 Feb 2010 00:54:10 GMT",
          "friends": [{
              "id": 1,
              "name": "Владимир Смирнов",
              "phone": "+70955949774"
          }, {
              "id": 2,
              "name": "Тарас Алексеев",
              "phone": "+70954632584"
          }, {
              "id": 3,
              "name": "Артемий Попов",
              "phone": "+70953248918"
          }],
          "field": "field value"
      }, {
          "id": 7,
          "avatar": "images/user_7.png",
          "age": -6,
          "admin": true,
          "name": "Донат Михайлов",
          "company": "Compuamerica",
          "phone": "+70957017756",
          "email": "donat@compuamerica.com",
          "registerDate": "Sat, 21 Apr 2012 08:39:24 GMT",
          "friends": [{
              "id": 1,
              "name": "Моисей Зайцев",
              "phone": "+70958269157"
          }, {
              "id": 2,
              "name": "Илья Величко",
              "phone": "+70956511879"
          }, {
              "id": 3,
              "name": "Эдуард Лебедев",
              "phone": "+70958629056"
          }],
          "field": "field value"
      }, {
          "id": 8,
          "avatar": "images/user_8.png",
          "age": -9,
          "admin": false,
          "name": "Никита Яковлев",
          "company": "Infragraph",
          "phone": "+70958349396",
          "email": "nikita@infragraph.com",
          "registerDate": "Mon, 13 Jan 2003 05:03:14 GMT",
          "friends": [{
              "id": 1,
              "name": "Макар Щербаков",
              "phone": "+70950053645"
          }, {
              "id": 2,
              "name": "Борис Левченко",
              "phone": "+70953834779"
          }, {
              "id": 3,
              "name": "Михаил Колесников",
              "phone": "+70956620699"
          }],
          "field": "field value"
      }, {
          "id": 9,
          "avatar": "images/user_9.png",
          "age": 13,
          "admin": false,
          "name": "Валерий Васильев",
          "company": "Techtron",
          "phone": "+70952846819",
          "email": "valeriy@techtron.com",
          "registerDate": "Sun, 05 Jun 2011 20:02:48 GMT",
          "friends": [{
              "id": 1,
              "name": "Роман Чернов",
              "phone": "+70950709792"
          }, {
              "id": 2,
              "name": "Федор Никитин",
              "phone": "+70951796324"
          }, {
              "id": 3,
              "name": "Мартын Гусев",
              "phone": "+70958518571"
          }],
          "field": "field value"
      }, {
          "id": 10,
          "avatar": "images/user_10.png",
          "age": 23,
          "admin": false,
          "name": "Дмитрий Фролов",
          "company": "Generola",
          "phone": "+70951285493",
          "email": "dmitriy@generola.com",
          "registerDate": "Sun, 25 Jan 2004 02:05:21 GMT",
          "friends": [{
              "id": 1,
              "name": "Мартын Гусев",
              "phone": "+70956409077"
          }, {
              "id": 2,
              "name": "Вадим Савченко",
              "phone": "+70958853957"
          }, {
              "id": 3,
              "name": "Денис Данилов",
              "phone": "+70957331023"
          }],
          "field": "field value"
      }, {
          "id": 11,
          "avatar": "images/user_11.png",
          "age": 13,
          "admin": true,
          "name": "Марк Егоров",
          "company": "iOptystix",
          "phone": "+70953053414",
          "email": "mark@ioptystix.com",
          "registerDate": "Wed, 19 Nov 1980 18:56:38 GMT",
          "friends": [{
              "id": 1,
              "name": "Константин Павлов",
              "phone": "+70952549266"
          }, {
              "id": 2,
              "name": "Гордей Соколов",
              "phone": "+70958584105"
          }, {
              "id": 3,
              "name": "Яков Олейник",
              "phone": "+70953394414"
          }],
          "field": "field value"
      }, {
          "id": 12,
          "avatar": "images/user_12.png",
          "age": -10,
          "admin": false,
          "name": "Оскар Данилов",
          "company": "Sontopia",
          "phone": "+70959186026",
          "email": "oskar@sontopia.com",
          "registerDate": "Fri, 13 Aug 2004 23:14:14 GMT",
          "friends": [{
              "id": 1,
              "name": "Илларион Поляков",
              "phone": "+70958012109"
          }, {
              "id": 2,
              "name": "Вячеслав Захаров",
              "phone": "+70956284147"
          }, {
              "id": 3,
              "name": "Алексей Ткаченко",
              "phone": "+70956435863"
          }],
          "field": "field value"
      }, {
          "id": 13,
          "avatar": "images/user_13.png",
          "age": 8,
          "admin": false,
          "name": "Клим Пономаренко",
          "company": "Syssoft",
          "phone": "+70954495043",
          "email": "klim@syssoft.com",
          "registerDate": "Fri, 15 Mar 1991 12:44:52 GMT",
          "friends": [{
              "id": 1,
              "name": "Артем Смирнов",
              "phone": "+70958924813"
          }, {
              "id": 2,
              "name": "Виктор Рубан",
              "phone": "+70953345465"
          }, {
              "id": 3,
              "name": "Николай Макаров",
              "phone": "+70958101509"
          }],
          "field": "field value"
      }, {
          "id": 14,
          "avatar": "images/user_14.png",
          "age": 33,
          "admin": false,
          "name": "Лев Сергеев",
          "company": "Allnet",
          "phone": "+70954837040",
          "email": "lev@allnet.com",
          "registerDate": "Thu, 05 Sep 1974 05:17:11 GMT",
          "friends": [{
              "id": 1,
              "name": "Ян Богданов",
              "phone": "+70959719852"
          }, {
              "id": 2,
              "name": "Яков Олейник",
              "phone": "+70954388796"
          }, {
              "id": 3,
              "name": "Казимир Макаров",
              "phone": "+70959931920"
          }],
          "field": "field value"
      }, {
          "id": 15,
          "avatar": "images/user_15.png",
          "age": 0,
          "admin": false,
          "name": "Ян Богданов",
          "company": "Proline",
          "phone": "+70959811583",
          "email": "yan@proline.com",
          "registerDate": "Fri, 08 Oct 1999 14:37:59 GMT",
          "friends": [{
              "id": 1,
              "name": "Игнат Волков",
              "phone": "+70958350040"
          }, {
              "id": 2,
              "name": "Григорий Васильев",
              "phone": "+70956950787"
          }, {
              "id": 3,
              "name": "Валентин Шевченко",
              "phone": "+70953038579"
          }],
          "field": "field value"
      }, {
          "id": 16,
          "avatar": "images/user_16.png",
          "age": 32,
          "admin": false,
          "name": "Гавриил Мельник",
          "company": "Technogra",
          "phone": "+70952595281",
          "email": "gavriil@technogra.com",
          "registerDate": "Sun, 28 Aug 1977 03:08:35 GMT",
          "friends": [{
              "id": 1,
              "name": "Леонард Никитин",
              "phone": "+70958590623"
          }, {
              "id": 2,
              "name": "Сергей Поляков",
              "phone": "+70957923587"
          }, {
              "id": 3,
              "name": "Рудольф Логинов",
              "phone": "+70953619748"
          }],
          "field": "field value"
      }, {
          "id": 17,
          "avatar": "images/user_17.png",
          "age": 49,
          "admin": false,
          "name": "Ефим Марченко",
          "company": "Fibrotouch",
          "phone": "+70951410612",
          "email": "efim@fibrotouch.com",
          "registerDate": "Tue, 08 May 1979 01:39:19 GMT",
          "friends": [{
              "id": 1,
              "name": "Евгений Новиков",
              "phone": "+70953519073"
          }, {
              "id": 2,
              "name": "Гарри Морозов",
              "phone": "+70956726429"
          }, {
              "id": 3,
              "name": "Михаил Колесников",
              "phone": "+70954199005"
          }],
          "field": "field value"
      }, {
          "id": 18,
          "avatar": "images/user_18.png",
          "age": -17,
          "admin": false,
          "name": "Борис Левченко",
          "company": "Nanobanc",
          "phone": "+70959552868",
          "email": "boris@nanobanc.com",
          "registerDate": "Wed, 22 Jun 1983 15:23:05 GMT",
          "friends": [{
              "id": 1,
              "name": "Роман Чернов",
              "phone": "+70952105519"
          }, {
              "id": 2,
              "name": "Вячеслав Захаров",
              "phone": "+70956259917"
          }, {
              "id": 3,
              "name": "Виктор Рубан",
              "phone": "+70954340308"
          }],
          "field": "field value"
      }, {
          "id": 19,
          "avatar": "images/user_19.png",
          "age": 15,
          "admin": false,
          "name": "Гарри Морозов",
          "company": "Superscope",
          "phone": "+70956739864",
          "email": "garri@superscope.com",
          "registerDate": "Fri, 29 Oct 2010 15:06:25 GMT",
          "friends": [{
              "id": 1,
              "name": "Осип Григорьев",
              "phone": "+70959781108"
          }, {
              "id": 2,
              "name": "Мартин Козлов",
              "phone": "+70959291544"
          }, {
              "id": 3,
              "name": "Леонард Никитин",
              "phone": "+70958871096"
          }],
          "field": "field value"
      }, {
          "id": 20,
          "avatar": "images/user_20.png",
          "age": 9,
          "admin": true,
          "name": "Вениамин Нестеренко",
          "company": "Navivacs",
          "phone": "+70954800459",
          "email": "veniamin@navivacs.com",
          "registerDate": "Sat, 04 Oct 1975 18:54:24 GMT",
          "friends": [{
              "id": 1,
              "name": "Руслан Борисов",
              "phone": "+70954052334"
          }, {
              "id": 2,
              "name": "Прохор Титов",
              "phone": "+70951629627"
          }, {
              "id": 3,
              "name": "Моисей Зайцев",
              "phone": "+70957270806"
          }],
          "field": "field value"
      }]
  };
  var smallArray = [];
  var bigArray = bigObj.result;
  var str = '';
  var num = 1;
  
  underscoreIsObject = function(obj) {
      return obj === Object(obj);
    };
  
  instanceofIsObject = function(obj) {
      return obj instanceof Object;
    };
  typeofIsObject = function (obj) {
  typeof obj === "object" 
  };

};
</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
_.isObject
underscoreIsObject(smallObj);
underscoreIsObject(bigObj);
underscoreIsObject(smallArray);
underscoreIsObject(bigArray);
underscoreIsObject(str);
underscoreIsObject(num);
pending…
instanceof
instanceofIsObject(smallObj);
instanceofIsObject(bigObj);
instanceofIsObject(smallArray);
instanceofIsObject(bigArray);
instanceofIsObject(str);
instanceofIsObject(num);
pending…
typeof
typeofIsObject(smallObj);
typeofIsObject(bigObj);
typeofIsObject(smallArray);
typeofIsObject(bigArray);
typeofIsObject(str);
typeofIsObject(num);
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