coucou

Benchmark created on


Setup

function deepEquals(...o) {
  if (o.length <= 1) return true;
  for (let index = 1; index < o.length; index++) {
    if (!_deepEquals(o[0], o[index])) return false;
  }
  return true;
}

function _deepEquals(o1, o2) {
  if (o1 === o2) return true;
  if ((o1 && !o2) || (o2 && !o1)) return false;
  if (typeof o1 !== typeof o2) return false;
  if (typeof o1 !== "object") return false;

  // Objects can have different keys if the values are undefined
  for (const key in o2) {
    if (!(key in o1) && o2[key] !== undefined) {
      return false;
    }
  }

  for (const key in o1) {
    if (typeof o1[key] !== typeof o2[key]) return false;
    if (typeof o1[key] === "object") {
      if (!_deepEquals(o1[key], o2[key])) return false;
    } else {
      if (o1[key] !== o2[key]) return false;
    }
  }

  return true;
}

Test runner

Ready to run.

Testing in
TestOps/sec
test1
const n = 10000;
const obj1 = {a:1,b:2,c:3,d:4}
const obj2 = {a:1,b:2,c:3,d:4}
let res = 0
for (let i=0; i<n;i++){
	res = deepEquals(obj1,obj2)
}
ready
test2
const n = 10000;
const obj1 = {a:1,b:2,c:3,d:4}
const obj2 = {a:1,b:2,c:3,d:4}
let res = 0
for (let i=0; i<n;i++){
	res = (obj1.a === obj2.a &&
	obj1.b === obj2.b &&
	obj1.c === obj2.c &&
	obj1.d === obj2.d)
}
ready

Revisions

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