object-empty-check

JavaScript performance comparison

Test case created by kamil-kielczewski

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let obj = {};

};
</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
A
for(var i in obj) return false; 
return true;
pending…
B
return JSON.stringify(obj) === '{}';
pending…
C
return Object.keys(obj).length === 0;
pending…
D
return Object.entries(obj).length === 0;
pending…
E
return Object.getOwnPropertyNames(obj).length === 0;
pending…
F
return Object.keys(obj).length === 0 && obj.constructor === Object;
pending…
G
return typeof obj === "undefined" || !Boolean(Object.keys(obj)[0]);
pending…
H
return Object.entries(obj).length === 0 && obj.constructor === Object;
pending…
I
return Object.values( obj  ).every( val => typeof val === "undefined" );
pending…
J
for (const key in obj) {
  if (hasOwnProperty.call(obj, key)) {
    return false
  }
}
return true;
pending…
K
for(var prop in obj) {
  if(obj.hasOwnProperty(prop)) {
    return false;
  }
}
return JSON.stringify(obj) == JSON.stringify({});
pending…
L
for(var prop in obj) {
  if(obj.hasOwnProperty(prop))
    return false;
}
return true;
pending…
M
for (var k in obj)
{ 
  if ( obj.hasOwnProperty(k) )
  { 
    return false;
  } 
}
return true;
pending…
N
return Object.getOwnPropertyNames(obj).length === 0 &&
Object.getOwnPropertySymbols(obj).length === 0 &&
Object.getPrototypeOf(obj) === Object.prototype;
pending…
O
return !(Object.getOwnPropertyNames != undefined ? Object.getOwnPropertyNames(obj).length != 0 : (function(){for(var key in obj) break; return (key != null) && (key != undefined);})());
pending…

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

0 Comments