Check Empty Object

JavaScript performance comparison

Test case created by Chris Waddington

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.1.1/lodash.min.js"></script>
<script src="https://arasatasaygin.github.io/is.js/scripts/is.js"></script>
<script>
var lodash = _.noConflict();
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var obj = {};
  for (i = 0; i < 10000; i++) {
    obj["abc_" + i] = i;
  }

};
</script>

Preparation code output

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
is.js
is.empty(obj)
pending…
jquery
jQuery.isEmptyObject(obj);
pending…
lodash
lodash.isEmpty(obj);
pending…
underscore
_.isEmpty(obj);
pending…
Object.getOwnPropertyNames
Object.getOwnPropertyNames(obj).length === 0;
pending…
JSON.stringify
JSON.stringify(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