string literal vs array join
Date tested:
3 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36
Test name
Executions per second
array.join
2590.5 Ops/sec
string literal
5183.7 Ops/sec
string concatenation
6919.6 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var arr = Array(50000) .fill(1) .map(() => 'A' + Math.ceil(Math.random() * 100));
Tests:
array.join
var res=arr.join('; ');
string literal
var finalString2 = arr.reduce((res, item) => { return `${res}; ${item}`; }, '');
string concatenation
var finalString3 = arr.reduce((res, item) => { return res + '; ' + item; }, '');
Open this result on MeasureThat.net