const vs join

JavaScript performance comparison

Revision 2 of this test case created

Info

For this stack overflow question

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var hashStore = new Array(21).join("#");
    var Fiveup ;
    var Tenup ;
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
const
Fiveup = "";
for (var i=0;i<100;i+=hashStore.length) {
    Fiveup += hashStore.substring(0, Math.min(hashStore.length, 100-i));
}
Tenup = "";
for (var i=0;i<200;i+=hashStore.length) {
    Tenup += hashStore.substring(0, Math.min(hashStore.length, 200-i));
}
pending…
split
Fiveup = new Array(101).join('#');
Tenup = new Array(201).join('#');
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:

0 comments

Add a comment