classof (v2)

Revision 2 of this benchmark created on


Setup

var undefined = void(0);
    var V = new Number(42);
    var v = 42;
    var x = /x/;
    var opts = Object.prototype.toString;
    
    function f1(o){
    if(o === undefined) return "undefined";
    if(o === null) return "null";
    return opts.call(o).slice(8,-1);
    }
    
    function f2(o){
    if(o === undefined) return "undefined";
    if(o === null) return "null";
    if(typeof o === "number") return "Number";
    if(typeof o === "string") return "String";
    if(typeof o === "function") return "Function";
    if(typeof o === "boolean") return "Boolean";
    return opts.call(o).slice(8,-1);
    }
    
    function f3(o){
    if(o === undefined) return "undefined";
    if(o === null) return "null";
    if(typeof o !== "object"){
    if(typeof o === "number") return "Number";
    if(typeof o === "string") return "String";
    if(typeof o === "function") return "Function";
    if(typeof o === "boolean") return "Boolean";
    }
    return opts.call(o).slice(8,-1);
    }
    
    function f4(o){
    var t;
    if(o === null) return "null";
    if((t = typeof o) !== "object"){
    if(o === undefined) return "undefined";
    if(t === "number") return "Number";
    if(t === "string") return "String";
    if(t === "function") return "Function";
    if(t === "boolean") return "Boolean";
    }
    return opts.call(o).slice(8,-1);
    }
    
    function f5(o){
    var t;
    if(o === null) return "null";
    if((t = typeof o) !== "object"){
    if(t === "undefined") return "undefined";
    if(t === "number") return "Number";
    if(t === "string") return "String";
    if(t === "function") return "Function";
    if(t === "boolean") return "Boolean";
    }
    return opts.call(o).slice(8,-1);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
V 1
f1(V);
ready
v 1
f1(v);
ready
x 1
f1(x);
ready
V 3
f3(V);
ready
v 3
f3(v);
ready
x 3
f3(x);
ready
V 4
f4(V);
ready
v 4
f4(v);
ready
x 4
f4(x);
ready
V 5
f5(V);
ready
v 5
f5(v);
ready
x 5
f5(x);
ready

Revisions

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