Strings Concatenation With Separator: join, +, concat

Benchmark created on


Setup

function testJoin(...names) {
    const list = []

    for (const item of names) {
        list.push(item)
    }

    return list.join(' ')
}

function testAdd(...names) {
    const [name, ...otherNames] = names
    var list = name

    for (const item of otherNames) {
        list += ' '+ item
    }

    return list
}

const concat = String.prototype.concat.bind(String.prototype)

function testConcat(...names) {
    const [name, ...otherNames] = names
    var list = name

    for (const item of otherNames) {
        list = concat(list, ' '+ item)
    }

    return list
}

const data = {
    data1() {
        return [
            `Component1-${Date.now()} std-flex std-flex-column std-flex-align-center std-overflow-hidden`,
            `Component2-${Date.now()}`,
        ]
    },
    data2() {
        return [
            `Component1-${Date.now()} std-flex std-flex-column std-flex-align-center std-overflow-hidden`,
            `Component2-${Date.now()} std-flex std-flex-column std-flex-align-center std-overflow-hidden`,
        ]
    },
    data3() {
        return [
            `Component1-${Date.now()} std-flex std-flex-column std-flex-align-center std-overflow-hidden`,
            `Component2-${Date.now()} std-flex std-flex-column std-flex-align-center std-overflow-hidden`,
            `Component3-${Date.now()} std-flex std-flex-column std-flex-align-center std-overflow-hidden`,
            `Component4-${Date.now()} std-flex std-flex-column std-flex-align-center std-overflow-hidden`,
        ]
    },
}

Test runner

Ready to run.

Testing in
TestOps/sec
Join
testJoin(...data.data1())
testJoin(...data.data2())
testJoin(...data.data3())
ready
Add
testAdd(...data.data1())
testAdd(...data.data2())
testAdd(...data.data3())
ready
Concat
testConcat(...data.data1())
testConcat(...data.data2())
testConcat(...data.data3())
ready

Revisions

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