Script Preparation code:
AخA
 
function isEmpty1(obj) {
    return (Object.keys(obj).length === 0) && obj.constructor === Object;
}
function isEmpty2(obj) {
    for (key in obj) {
      if (Object.prototype.hasOwnProperty.call(obj, key)) {
        return false;
      }
    }
    return true;
}
var a = {};
Tests:
  • isEmpty1

     
    var count = 1000;
    for (i=0;i<count;i++) isEmpty1(a);
  • isEmpty2

     
    var count = 1000;
    for (i=0;i<count;i++) isEmpty2(a);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    isEmpty1
    isEmpty2

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Chrome 95 on Windows
View result in a separate tab
Test name Executions per second
isEmpty1 2611.9 Ops/sec
isEmpty2 7837.2 Ops/sec