Primitive value string vs Wrapper Object String - valueOf()

Benchmark created on


Preparation HTML

str1.valueOf(); = <div id="id1"></div><br>
str2.valueOf(); = <div id="id2"></div>

Setup

var str1 = "Hello";
    var str2 = new String("Hello");
    
    var i = "(idle)",
        k = "(idle)";

Teardown


    var x = document.getElementById("id1"); x.innerHTML = i;
    var y = document.getElementById("id2"); y.innerHTML = k;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Primitive value string str1.valueOf()
i = str1.valueOf();
ready
Wrapper object string str2.valueOf()
k = str2.valueOf();
ready

Revisions

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