eqeqeq vs eq

JavaScript performance comparison

Revision 7 of this test case created by Mike McCaughan

Info

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

Preparation code

<script>
  var u, 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…
u eqeqeq null
if (u === null) {
  e = '';
}
pending…
u eqeq null
if (u == null) {
  e = '';
}
pending…
u isU
if (isU(u)) {
  e = '';
}
pending…
u isN
if (isN(u)) {
  e = '';
}
pending…
u isUN
if (isUN(u)) {
  e = '';
}
pending…
u isUNfn
if (isUNfn(u)) {
  e = '';
}
pending…
u isUNb
if (isUNb(u)) {
  e = '';
}
pending…
u
if (u) {
  e = '';
}
pending…
not u
if (!u) {
e = '';
}
pending…
not not u
if ( !! u) {
  e = '';
}
pending…
not not not u
if ( !! !u) {
  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:

2 comments

Mike McCaughan (revision owner) commented :

Is it me or are those Chrome scores a little iffy? How could !!!n and u === null take exactly the same number of operations per second, down to a single op/s? Something's off with the test runner...

John-David Dalton commented :

Something's off with the test runner...

Naw, part of it is explained in the FAQ: http://jsperf.com/faq#browserscope

The other part is that we recently normalized on the slowest indistinguishable live and charted result because Browserscope lacks the context of margin of error. This has now changed so that only the chart results are normalized.

Add a comment