typeof vs tostring

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function checkTypeof(a,b) {
        return typeof a == 'string' ? a == b.toString() : a == b;
    }
    function checkTostring(a,b) {
        return a.toString() == b.toString();
    }
};
</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
tostring
checkTostring('12', 12);
checkTostring(12, 12);
 
pending…
typeof
checkTypeof('12', 12);
checkTypeof(12, 12);
 
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment