eqeqeq vs eq
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
n eqeqeq null |
|
pending… |
n eqeq null |
|
pending… |
isU |
|
pending… |
isN |
|
pending… |
isUN |
|
pending… |
isUNfn |
|
pending… |
isUNb |
|
pending… |
n |
|
pending… |
not n |
|
pending… |
not not n |
|
pending… |
not not not n |
|
pending… |
u eqeqeq null |
|
pending… |
u eqeq null |
|
pending… |
u isU |
|
pending… |
u isN |
|
pending… |
u isUN |
|
pending… |
u isUNfn |
|
pending… |
u isUNb |
|
pending… |
u |
|
pending… |
not u |
|
pending… |
not not u |
|
pending… |
not not not u |
|
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:
- Revision 1: published
- Revision 2: published
- Revision 3: published by Mike McCaughan
- Revision 4: published by Mike McCaughan
- Revision 5: published by Mike McCaughan
- Revision 6: published by Mike McCaughan
- Revision 7: published by Mike McCaughan
- Revision 8: published
2 comments
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...
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.