jquery vs utility vs lodash isPlainObject (v17)

Revision 17 of this benchmark created on


Description

Utility will try to avoid failures like

var obj = {nodeType: 1}

But what is the performance cost?

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.1/lodash.min.js">
</script>
<script src="//utility-js.googlecode.com/files/utility3.js"></script>

Setup

var b = [{}, function() {}, [], "", 1, new Date(), /abc/, new Error(), $, $(), $u, $u(), undefined, null, document],
        c= [window], // Firefox throws an error if we walk this object
        a = [].concat(b).concat(c);
    
    b.forEach(function(obj) {
      try {
        Object.getOwnPropertyNames(obj).forEach(function(name) {
          var d, t;
    
          try {
            a.push(obj[name]);
          } catch (e) {}
        });
      } catch (e) {}
    });
    
    function isPlainObject(o) {
      return Object.prototype.toString.call(o) === '[object Object]';
    }

Test runner

Ready to run.

Testing in
TestOps/sec
jquery
a.forEach(function(o) {
  $.isPlainObject(o);
});
ready
utility
a.forEach(function(o) {
  $u.isPlainObject(o);
});
ready
lodash
a.forEach(function(o) {
  _.isPlainObject(o);
});
ready
alt
a.forEach(function(o) {
  isPlainObject(o);
});
ready

Revisions

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