Comparison of comparisons

JavaScript performance comparison

Test case created by minitech

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.

Testing in unknown unknown
Test Ops/sec
Identity
a === b;
a === c;
pending…
Equality
a == b;
a == c;
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:

5 comments

Ben commented :

Identity is infinitely faster than equality. Checkout my results for proof.

http://screencast.com/t/II6KUTyqr

billy commented :

Agreed with Ben, chrome will optimize this.

Lonesome Walker commented :

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 ;)

Tim Down commented :

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.

Jordan commented :

I love how BlackBerry WebKit managed to be faster than anything else using ===...

Add a comment