Comparison of comparisons

JavaScript performance comparison

Revision 24 of this test case created by Joshua Koudys

Info

Compares the performance of == and ===. Added some extra checks to compare a simple coercion scenario -- boolean coercion vs explicit cast w/ ===.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = 'hello';
    var b = 'world';
    var c = 'hello';
    var d = "";
    var t = true;
    var ti = 1;
    var f = false;
    var fi = 0;
    var bignumber = 123456789;
    var othernumber = 987654321;
};
</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…
Implied coercion
ti == t;
fi == f;
 
pending…
Explicit cast
Boolean(ti) === t;
Boolean(fi) === f;
pending…
Coercion (string)
a == t;
d == f;
pending…
Explicit cast (string)
Boolean(a) === t;
Boolean(d) === f;
pending…
Implied coercion (bigger numbers)
bignumber == t;
othernumber == f;
pending…
Explicit cast (bigger numbers)
Boolean(bignumber) === t;
Boolean(othernumber) === f;
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