Comparison of comparisons
JavaScript performance comparison
Info
Compares the performance of == and ===.
Preparation code
<script>
Benchmark.prototype.setup = function() {
var a = 'hello';
var b = 'world';
var c = 'hello';
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Identity |
|
pending… |
Equality |
|
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 by minitech
- Revision 4: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
4 comments
Identity is infinitely faster than equality. Checkout my results for proof.
http://screencast.com/t/II6KUTyqr
Agreed with Ben, chrome will optimize this.
fyi in ie9:
Identity a === b; a === c; 20,206,844 ±0.23%25% slower
Equality a == b; a == c; 27,134,240 ±0.68%fastest
Well, my firefox says: Identity a === b; a === c; 819,540,161 ±0.26%fastest
Equality a == b; a == c; 38,048,899 ±0.50%95% slower
So, it depends ;)
Clearly it varies with browser. Since these particular comparisons are defined by the ECMAScript spec to run precisely the same steps, this is an unsurprising result: it's bound to be engine-dependent.