isArray - duck typing vs. instanceof (v5)

Revision 5 of this benchmark created on


Description

This test is motivated by the use of duck typing in the current underscore.js implementation for _.isType() functions.

I believe we should not care about the cross frame edge case - take a look at the performance.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

$(document).ready(function($) {
    
    
    
        
        $("#icon_0").click( function(){
                var id = $("#ListaMenu");
        
                var ativo  = $("#ListaMenu").hasClass("hide")? true : false;
    
                if(ativo == true){
                        id.removeClass("hide").addClass("show");
                }else{
                        id.removeClass("show").addClass("hide");
                }
    
        })
    
        $("#icon_0").bind({
                        'focusin' : function(Event) {
                        
                                console.log("ativo");
                        },
                        'focusout' : function(Event) {
    
                                console.log("saiu");
                                
                        }
                });
    
    
    
    
    });

Test runner

Ready to run.

Testing in
TestOps/sec
duck typing
!! (obj0 && obj0.concat && obj0.unshift && !obj0.callee); !! (obj1 && obj1.concat && obj1.unshift && !obj1.callee); !! (obj2 && obj2.concat && obj2.unshift && !obj2.callee); !! (obj3 && obj3.concat && obj3.unshift && !obj3.callee);
ready
instanceof
obj0 instanceof Array;
obj1 instanceof Array;
obj2 instanceof Array;
obj3 instanceof Array;
ready
secure cross frame
toString.call(obj0) === '[object Array]';
toString.call(obj1) === '[object Array]';
toString.call(obj2) === '[object Array]';
toString.call(obj3) === '[object Array]';

// http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
ready

Revisions

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