typeString vs toType

JavaScript performance comparison

Test case created

Preparation code

<script>
  var toString = {}.toString;
 
  function typeString (v) {
      return v == null ? String(v) : toString.call(v).slice(8, -1);
  }
 
  function toType(obj) {
    return obj == null ? String(obj) : ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1]
  }
 
</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
typeString
typeString(null);
typeString(undefined);
typeString({});
typeString("");
typeString(2);
 
pending…
toType
toType(null);
toType(undefined);
toType({});
toType("");
toType(2);
 
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment