Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JS String '+' same v.s. different strings
Is there a difference in performance over many iterations of string concatenation if the string being added is the same or different each time?
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0
Browser:
Firefox 109
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Same string added each loop
360294.2 Ops/sec
Different string added each loop
10157.2 Ops/sec
Script Preparation code:
var nLoops = 1000;
Tests:
Same string added each loop
var fragmentToAdd = Math.random(); var str = ''; for (var i = 0; i < nLoops; i++) { // Just to equalize the work done in each test Math.random(); str += fragmentToAdd; }
Different string added each loop
var str = ''; for (var i = 0; i < nLoops; i++) { str += Math.random(); }