Primitive value string vs Wrapper Object String - length

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code

str1.length = <div id="id1"></div><br>
str2.length = <div id="id2"></div><br>
str3.length = <div id="id3"></div>

      
<script>
Benchmark.prototype.setup = function() {
  var Token = String;
  
  var str1 = "Hello";
  var str2 = new String("Hello");
  var str3 = new Token ("Hello");
  
  var i = "(idle)",
      k = "(idle)",
      j = "(idle)";
  

};

Benchmark.prototype.teardown = function() {
  var x = document.getElementById("id1"); x.innerHTML = i;
  var y = document.getElementById("id2"); y.innerHTML = k;
  var z = document.getElementById("id3"); z.innerHTML = j;

};
</script>

Preparation code output

str1.length = <div id="id1"></div><br> str2.length = <div id="id2"></div><br> str3.length = <div id="id3"></div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Primitive value string str1.length
i = str1.length;
pending…
Wrapper object string str2.length
k = str2.length;
pending…
Alias of Wrapper object string str2.length
j = str3.length;
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.

0 Comments

str1.length =

str2.length =

str3.length =