Primitive value string vs Wrapper Object String - length
JavaScript performance comparison
Preparation code
str1.length = <div id="id1"></div><br>
str2.length = <div id="id2"></div>
<script>
Benchmark.prototype.setup = function() {
var str1 = "Hello";
var str2 = new String("Hello kummmu kummu kummmmmu ");
var i = "(idle)",
k = "(idle)";
};
Benchmark.prototype.teardown = function() {
var x = document.getElementById("id1"); x.innerHTML = i;
var y = document.getElementById("id2"); y.innerHTML = k;
};
</script>
Preparation code output
str1.length =
str2.length =
str2.length =
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Primitive value string str1.length |
|
pending… |
Wrapper object string str2.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. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published
- Revision 3: published
- Revision 4: published
0 comments