js concat-vs-join

JavaScript performance comparison

Test case created by lexxpavlov

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var str = '';
    var arr = [];
    var fast = 10000,
        slow = 100000;
    var sample1 = "test";
    var sample2 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
};
</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
concat-short-fast
for (i = 0; i < fast; i++) str += sample1;
pending…
concat-long-fast
for (i = 0; i < fast; i++) str += sample2;
pending…
concat-short-slow
for (i = 0; i < slow; i++) str += sample1;
pending…
concat-long-slow
for (i = 0; i < slow; i++) str += sample2;
pending…
join-short-fast
for (i = 0; i < fast; i++) arr[arr.length] = sample1;
str = arr.join('');
pending…
join-long-fast
for (i = 0; i < fast; i++) arr[arr.length] = sample2;
str = arr.join('');
pending…
join-short-slow
for (i = 0; i < slow; i++) arr[arr.length] = sample1;
str = arr.join('');
pending…
join-long-slow
for (i = 0; i < slow; i++) arr[arr.length] = sample2;
str = arr.join('');
pending…

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

Compare results of other browsers

0 comments

Add a comment