eqeqeq vs eq

JavaScript performance comparison

Revision 5 of this test case created by Mike McCaughan

Info

Check performance of === vs == in varying situations.

Preparation code

<script>
  var n = null,
      e = '',
      isU = function(v) {
      return typeof v === 'undefined';
      },
      isN = function(v) {
      return v === null;
      },
      isUN = function(v) {
      return typeof v !== 'undefined' && v !== null;
      },
      isUNfn = function(v) {
      return !isU(v) && !isN(v);
      },
      isUNb = function(v) {
      return !!!v;
      };
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
n eqeqeq null
if (n === null) {
  e = '';
}
pending…
n eqeq null
if (n == null) {
  e = '';
}
pending…
isU
if (isU(n)) {
  e = '';
}
pending…
isN
if (isN(n)) {
  e = '';
}
pending…
isUN
if (isUN(n)) {
  e = '';
}
pending…
isUNfn
if (isUNfn(n)) {
  e = '';
}
pending…
isUNb
if (isUNb(n)) {
  e = '';
}
pending…
n
if (n) {
  e = '';
}
pending…
not n
if (!n) {
  e = '';
}
pending…
not not n
if (!!n) {
  e = '';
}
pending…
not not not n
if (!!!n) {
  e = '';
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment