Join vs Stringify vs angular.equals

Benchmark created on


Setup

const myValues1 = ['test1', 'test2', 'test3'];
const myValues2 = ['test1', 'test2', 'test3'];

Test runner

Ready to run.

Testing in
TestOps/sec
Join
if (myValues1.join(';') === myValues2.join(';')) {
	return true;
}
ready
Stringify
if (JSON.stringify(myValues1) === JSON.stringify(myValues2)) {
	return true;
}
ready
angular.equals
if (myValues1.length === myValues2.length) {
  for (let key = 0; key < myValues1.length; key++) {
    if (myValues1[key] === myValues2[key]) {
      return false;
    }
  }
  return true;
}
return false;
ready
angular.equals declare length first
const length = myValues1.length;
if (length === myValues2.length) {
  for (let key = 0; key < length; key++) {
    if (myValues1[key] === myValues2[key]) {
      return false;
    }
  }
  return true;
}
return false;
ready

Revisions

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