concat vs array (v2)

Revision 2 of this benchmark created on


Description

Testing the building of a string

Setup

var sample = " string",
    str = "",
    arr = [],
    a = 5000,
    b = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
array with join
for (; b < a; b += 1) {
sample = sample + "a";
arr.push(sample);
}
ready
string concat
for (; b < a; b += 1) {
str += sample;
}
ready
array build with join
for (; b < a; b += 1) {
arr.push(sample);
}
arr = arr.join("");
ready
array build with string concat
for (; b < a; b += 1) {
sample = sample + "a";
arr.push(sample);
}
ready
string with extra concat
for (; b < a; b += 1) {
sample = sample + "a";
str += sample;
}
ready
array build with extra concat and join
for (; b < a; b += 1) {
sample = sample + "a";
arr.push(sample);
}
arr = arr.join("");
ready

Revisions

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