concat vs array (v3)

Revision 3 of this benchmark created on


Description

Testing the building of a string

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
array build
for (; b < a; b += 1) {
    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);
}
arrjoin = 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);
}
arrjoin = arr.join("");
ready

Revisions

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