Detect Native DOM Element via noteType vs. instanceof

JavaScript performance comparison

Test case created by ryanve

Info

See: Safest way to detect native DOM element?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var isElementInstance = function(ukn) {
        return ukn instanceof Element;
    };
    var isElementNode = function(ukn) {
        return 1 === ukn.nodeType;
    };
    var body = document.body;
};
</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
instanceof
isElementInstance(body);
pending…
nodeType
isElementNode(body);
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