Cast To String (v11)

Revision 11 of this benchmark created by caller on


Setup

function t1(x) {
    return String(x);
  }
  
  function t2(x) {
    return new String(x);
  }
  
  function t3(x) {
    return x + '';
  }
  
  function t4(x) {
    return '' + x;
  }
  
  function t5(x) {
    return x.toString();
  }
  
  var o = {
    toString: function() {
      return "87";
    }
  };

Test runner

Ready to run.

Testing in
TestOps/sec
Post Concat Empty String
t4(87)
ready
Pre Concat Empty String from obj.toString
t3(o)
ready
toString Method
t5(87)
ready
Pre Concat Empty String
t3(87)
ready
String Instance
t2(87)
ready
String Factory
t1(87)
ready

Revisions

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