typeof-test-case
JavaScript performance comparison
Info
Three different fonctions for typeOf
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function typeOf_match(obj){return({}).toString.call(obj).match(/\s(\w+)/)[1]}
function typeOf_jquery(obj){
var c2t={"[object Boolean]":"Boolean","[object Number]":"Number","[object String]":"String","[object Function]":"Function","[object Array]":"Array","[object Date]":"Date","[object RegExp]":"RegExp","[object Object]":"Object"};
return obj==null?String(obj):c2t[({}).toString.call(obj)]||"object";
}
function typeOf_slice(obj) {return({}).toString.call(obj).slice(8,-1)}
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Match |
|
pending… |
jQuery (clone) |
|
pending… |
jQuery (original) |
|
pending… |
Slice |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments