Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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
Benchmark engine:
Benchmark.js
Same string added each loop
360K/s
Different string added each loop
10K/s
View exact numbers
Test name
Executions per second
✓
Same string added each loop
360,294 Ops/sec
Different string added each loop
10,157 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(); }