Comparison of object type-checking methods (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
var obj = {
  one: 1,
  two: 2,
  three: 3
};
var a = (typeof obj == "object");
var obj = "this is a string";
var a = (typeof obj == "object");
ready
underscore
var obj = {
  one: 1,
  two: 2,
  three: 3
};
var a = (obj === Object(obj));
var obj = "this is a string";
var a = (obj === Object(obj));
ready
angular.isObject
var obj = {
  one: 1,
  two: 2,
  three: 3
};
var a = (angular.isObject(obj));
var obj = "this is a string";
var a = (angular.isObject(obj));
ready
constructor
var obj = {
  one: 1,
  two: 2,
  three: 3
};
var a = (obj.constructor && obj.constructor === Object);
var obj = "this is a string";
var a = (obj.constructor && obj.constructor === Object);
ready

Revisions

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