const vs join

JavaScript performance comparison

Revision 3 of this test case created

Info

For this stack overflow question

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var hashStore = '########################################';
    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 = hashStore.substring(0, 5);
Tenup = hashStore.substring(0, 10);
pending…
split
Fiveup = new Array(6).join('#');
Tenup = new Array(11).join('#');
pending…
loop
Fiveup = '';
for (var i = 0; i < 6; i++) {
  Fiveup += '#';
}

Tenup = '';
for (var j = 0; j < 11; j++) {
  Tenup += '#';
}
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