Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Native JS: concatenate string with + vs template literals vs String.concat2
(version: 0)
find best solution for concatenate 4 strings
Comparing performance of:
using plus operator vs using concat function vs using template literals
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var name = "name lkjasdl;fj la;sflk;asdjf l;kj l;aksdjfla;kjs lka;sdjf la;ksdjf l;aksdjfl ;askd l;aksjf als;kdjf la;skdjfl;aksdjfl;aksdfl;aksdjf l; l;aksdjf ;laskdjf l;aksdjf l;askdjfl;askdjf;laskdj fl;aksdjf las;kd fal;sdf al;skdfjla;ksdjfl;aksdjf la;skdjfla;ksdjfla;skdjfla;skdfjals;kdjfa;lskdfjals;kdfjal;skdfjals;kdfjal;skdfjal;skj a asd;lfkjasl;kd fl; kasdf l;askdj l;askdj ;ladskfja;lsdkfj al;sdkfj ;l asld;kfj as;ldkfja l;sdkfj al;skdfj as;ldkfj asl;dkf. l;asdkfj al;skdfj a;lkasdfj ;laksdfj a;sldkfj a;slasdflkj asl;dkfj asdl; asl;dkfj asl;dkfjasl;dkfj a;lsdfjla;skdfj al;sdkjf lk;sadf asl;kdfja s;ldkfj asl;dkfj als;kdfj als;kdfj a;lskdfj al;skdfj als;kdfj a;lskdfj as;lkdf. asldf asl;kdf als;dkf asld;kfjasl;dkfj asl;kdfaslkd fa;lskd aslk;dfj asl;dkfj als;dfkjasl;dkfj asl;kdfj als;kdfj asl;kdfj asl;kdf aslk;d fljasdfkjasldk;fja s;lkdfj al;skdfjal;ksdfj lak;sdf a;lskdfj l;askdfj l;askdfj a;lskdj alskdfja l;skdfj als;kdfj asd;lkfjasdl;kfasdjf al;skdfj a;lskdfj a;lskdfj als;kdfj al; as ldkfjas l;dkfj asl;dfajsl;kdfj asl;kdfj al;skdfj al;skdfj al;skdfj al;skdfj als;kdfj als;kdfj slkda asl;kdfj l;askdfj al;skdf alsk;df alsk;dfj as;lkdfj l;askdfj laskdf"; var id = "id name lkjasdl;fj la;sflk;asdjf l;kj l;aksdjfla;kjs lka;sdjf la;ksdjf l;aksdjfl ;askd l;aksjf als;kdjf la;skdjfl;aksdjfl;aksdfl;aksdjf l; l;aksdjf ;laskdjf l;aksdjf l;askdjfl;askdjf;laskdj fl;aksdjf las;kd fal;sdf al;skdfjla;ksdjfl;aksdjf la;skdjfla;ksdjfla;skdjfla;skdfjals;kdjfa;lskdfjals;kdfjal;skdfjals;kdfjal;skdfjal;skj a asd;lfkjasl;kd fl; kasdf l;askdj l;askdj ;ladskfja;lsdkfj al;sdkfj ;l asld;kfj as;ldkfja l;sdkfj al;skdfj as;ldkfj asl;dkf. l;asdkfj al;skdfj a;lkasdfj ;laksdfj a;sldkfj a;slasdflkj asl;dkfj asdl; asl;dkfj asl;dkfjasl;dkfj a;lsdfjla;skdfj al;sdkjf lk;sadf asl;kdfja s;ldkfj asl;dkfj als;kdfj als;kdfj a;lskdfj al;skdfj als;kdfj a;lskdfj as;lkdf. asldf asl;kdf als;dkf asld;kfjasl;dkfj asl;kdfaslkd fa;lskd aslk;dfj asl;dkfj als;dfkjasl;dkfj asl;kdfj als;kdfj asl;kdfj asl;kdf aslk;d fljasdfkjasldk;fja s;lkdfj al;skdfjal;ksdfj lak;sdf a;lskdfj l;askdfj l;askdfj a;lskdj alskdfja l;skdfj als;kdfj asd;lkfjasdl;kfasdjf al;skdfj a;lskdfj a;lskdfj als;kdfj al; as ldkfjas l;dkfj asl;dfajsl;kdfj asl;kdfj al;skdfj al;skdfj al;skdfj al;skdfj als;kdfj als;kdfj slkda asl;kdfj l;askdfj al;skdf alsk;df alsk;dfj as;lkdfj l;askdfj laskdf";
Tests:
using plus operator
for (let i = 0; i < 80000; ++i) { let result = id + ": 1, " + name + ": someItem"; }
using concat function
for (let i = 0; i < 80000; ++i) { let result = "".concat(id, ": 1, ", name, ": someItem"); }
using template literals
for (let i = 0; i < 80000; ++i) { let result = `${id}: 1, ${name}: someItem`; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
using plus operator
using concat function
using template literals
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
using plus operator
111.7 Ops/sec
using concat function
97.6 Ops/sec
using template literals
111.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what's being tested. **Benchmark Overview** The benchmark is comparing three different ways to concatenate strings in JavaScript: 1. **Using the `+` operator** 2. **Using the `concat()` function** 3. **Using template literals** The benchmark consists of a single variable, `id`, which is set to `"someId"` (not shown in the provided code), and another variable, `name`, which is also not shown. The benchmark creates a string by concatenating these two variables with some text. **Test Cases** There are three test cases: 1. **Using the `+` operator**: This test case uses the `+` operator to concatenate the strings. 2. **Using the `concat()` function**: This test case uses the `concat()` function to concatenate the strings. 3. **Using template literals**: This test case uses template literals (`${}`) to concatenate the strings. **Benchmark Results** The benchmark results show the performance of each method for 80000 iterations: 1. **Using the `+` operator**: The browser executed approximately 204 executions per second (with a slight variation). 2. **Using the `concat()` function**: The browser executed approximately 201 executions per second. 3. **Using template literals**: The browser executed approximately 182 executions per second. **Observations** Based on these results, it appears that: * Using the `+` operator is slightly faster than using the `concat()` function and template literals. * Template literals are slower than both of the other methods. These results may vary depending on the specific use case, JavaScript engine, and hardware platform. Keep in mind that this benchmark only measures the performance of these three string concatenation methods and does not account for potential factors like memory allocation, garbage collection, or CPU overhead.
Related benchmarks:
Concatenate random strings with + vs template literals vs String.concat
Native JS: string plus VS template string!
Native JS2: concatenate string with + vs template literals vs String.concat
string with + vs template literals vs String.concat 4 input
Comments
Confirm delete:
Do you really want to delete benchmark?