eqeqeq vs eq

JavaScript performance comparison

Revision 3 of this test case created by Mike McCaughan

Info

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

Preparation code

<script>
  var u = undefined,
      i = 0,
      a = "0",
      n = null,
      e = '',
  isU = function (v) { return typeof u === 'undefined'; },
  isN = function (v) { return u === null; },
  isUN = function (v) { return typeof u !== 'undefined' && u !== 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
u eqeqeq undefined
if (u === undefined) {
 e = '';
}
pending…
u eqeq undefined
if (u == undefined) {
 e = '';
}
pending…
typeof u eqeqeq 'undefined'
if (typeof u === 'undefined') {
 e = '';
}
pending…
typeof u eqeq 'undefined'
if (typeof u == 'undefined') {
 e = '';
}
pending…
i eqeqeq 0
if (i === 0) {
 e = '';
}
pending…
i eqeq 0
if (i == 0) {
 e = '';
}
pending…
i eqeqeq '0'
if (i === '0') {
 e = '';
}
pending…
i eqeq '0'
if (i == '0') {
 e = '';
}
pending…
a eqeqeq 0
if (a === 0) {
 e = '';
}
pending…
a eqeq 0
if (a == 0) {
 e = '';
}
pending…
a eqeqeq '0'
if (a === '0') {
 e = '';
}
pending…
a eqeqeq '0'
if (a == '0') {
 e = '';
}
pending…
n eqeqeq null
if (n === null) {
 e = '';
}
pending…
n eqeq null
if (n == null) {
 e = '';
}
pending…
n eqeqeq 0
if (n === 0) {
 e = '';
}
pending…
e eqeqeq ''
if (e === '') {
 e = '';
}
pending…
e eqeq ''
if (e == '') {
 e = '';
}
pending…
e.length eqeqeq 0
if (e.length === 0) {
 e = '';
}
pending…
e.length eqeqeq 0
if (e.length == 0) {
 e = '';
}
pending…
e.length !eqeq 0
if (e.length !== 0) {
 e = '';
}
pending…
e.length !eq 0
if (e.length != 0) {
 e = '';
}
pending…
e.length
if (e.length) {
 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:

0 comments

Add a comment