Script Preparation code:
x
 
var obj1 = {
  foo: 'bar'
};
var obj0 = {};
function isEmpty1(obj) {
  return !!obj && Object.keys(obj).length === 0 && obj.constructor === Object;
}
function isEmpty2(obj) {
  if (!obj || obj.constructor !== Object) {
    return false;
  }
  for (var key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
      return false;
    }
  }
  return true;
}
Tests:
  • isEmpty1

     
    var result1 = [];
    for (let i = 0; i < 100; i += 1) {
      result1[i] = i % 2 ? isEmpty1(obj1) : isEmpty1(obj0);
    }
  • isEmpty2

     
    var result2 = [];
    for (let i = 0; i < 100; i += 1) {
      result2[i] = i % 2 ? isEmpty2(obj1) : isEmpty2(obj0);
    }
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/96.0.4664.45 Safari/537.36
Chrome 96 on Windows
View result in a separate tab
Test name Executions per second
isEmpty1 29526.9 Ops/sec
isEmpty2 29051.8 Ops/sec