string concat + join vs unshift + join (2)
Date tested:
5 months ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Test name
Executions per second
string concat + join
10527600.0 Ops/sec
unshift + join
5708046.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
function case1() { var el = 'test'; var arr = ['foo', 'bar']; return el + arr.join(','); } function case2() { var el = 'test'; var arr = ['foo', 'bar']; arr.unshift(el); return arr.join(','); }
Tests:
string concat + join
case1()
unshift + join
case2()
Open this result on MeasureThat.net