Cast To String (v13)

Revision 13 of this benchmark created 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 t3z(x) {
  var z='';
    return x + z;
  }
  
  function t4z(x) {
  var z='';
    return z + x;
  }
  
  
  function t5(x) {
    return x.toString();
  }
  
  var o = {
    toString: function() {
      return "87";
    }
  };

Test runner

Ready to run.

Testing in
TestOps/sec
String Factory
t1(87)
ready
String Instance
t2(87)
ready
Pre Concat Empty String
t3(87)
ready
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 z
t3z(87)
ready
Post Concat Empty String z
t4z(87)
ready
Post Concat Empty String z
t3z("test")
ready
Pre Concat Empty String z
t4z("test")
ready
Pre Concat Empty String
t3("test")
ready
Post Concat Empty String
t4("test")
ready

Revisions

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