Concatenación 2

Prueba para concatenación de cadenas mediante el uso de arrays.

HTML

<h2>
Method 2. Concatenation with array
</h2>

<table>
    <tr id="data">
        <th>Results</th>
    </tr>
</table>

<p>
    <a href="https://jsfiddle.net/juglan/fyhsb0s2/">Method 1</a> |
    <a href="https://jsfiddle.net/juglan/hsuwzb3o/">Method 3</a> |
	<a href="https://jsfiddle.net/juglan/vtyjw1ub/">Method 4</a>
</p>

CSS

* {
    font-family: Tahoma, Arial, Verdana;
}

td,
th {
    border: 1px solid #666;
    padding: 4px 8px;
}

th {
    background-color: #E0E0E0;
}

table {
    border-collapse: collapse;
}

a {
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h2 {
    font-size: 18px;
}

JavaScript

function concatenate() {
    var text = [],
        values = ['12', '23', '34', '45', '56'];

    for (j = 0; j < 5; ++j) {
        text.push(values[j]);
    }

    text = text.join('');
}

function addResult(value, row, last) {
    var node = document.createElement(last ? 'th' : 'td'),
        textnode = document.createTextNode(value);

    node.appendChild(textnode);
    row.appendChild(node);
}

function test() {
    var roundTime = 0,
        row = document.getElementById('data'),
        lap, startTime, i, endTime, currentResult;

    for (lap = 0; lap < 10; ++lap) {
        startTime = new Date();
        for (i = 0; i < 10000000; ++i) {
            concatenate();
        }
        endTime = new Date();

        currentResult = endTime.getTime() - startTime.getTime()
        roundTime += currentResult;
        addResult(currentResult, row, false);
    }

    addResult((roundTime / 10) + 'ms', row, true);
}

test();