Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
String concatenation-2021
(version: 0)
Comparing performance of:
Plus operator vs using concat function vs using template literals vs Plus equal operator
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var stringArray = [ "vsYjQhWW81jNQ7u", "9KQsDJfCnT4JJrf", "YMzWT1Uco2T9AB5", "0zIgDBXDMZdieUl", "4hItfhLfRD2hLIr", "XYw1Yn8SgaBzinu", "XTTahL0gbmFMdGn", "P37CWiCns1khHEC", "OX9y0sHujRn5PUw", "6AbyX3ijO6P97YO", "7bvsCc3ITvImtBN", "P2sed2qtsAcnXzS", "cBGbf19syg5NOTV", "QyIS9bU2qR3JBIp", "GPWyqNbSVrtPmtb", "fY0efx4zYPQGDQI", "9tuLr9O9rAdPzl4", "KZBPVONDyhoyHza", "Z5cp2YdqX1KXfKr", "oVvcuBIwBK3UYpv", "HAmCThLXToNd3Nu", "0J6SewdwBHE84CX", "ilksZKDvADAIadh", "ruAMkLNbdVJhYWn", "ee5jBvvjMuUDPc9", "DbpaZ5DYi9Bd81Z", "sNDzqXdt51Lr5mK", "7fMDPfm2uXjBv4L", "aycPYpmNRyeVZk3", "zdK3VuV4M7Hpadi", "p5Q1fRRT0d3fYBY", "pxCCJbinLQkXnrp", "uvIKNLhS2UCXBnj", "ink06qCBXXrGuOC", "4ZO4RrfTXZHoOUK", "i00qnvR90HpNiav", "ZHVLiMDvuUNpRxe", "uJPMfad63OHKjti", "dpws1715LWCC8C8", "KEQ1GZKJ8Bc6Cnx", "tMjEJx6z5aMUBuh", "rXNqiz2zNKFuHcX", "hYufOwpLqcQEuA2", "YxEK8D2B5Zj6FWF", "GzaMRURbhtPvsbs", "dk48vbh36bTWoDh", "ElOCc5EmYU0n0iF", "IdrIh7WYyneiYSf", "muqU7uRJpuHC8zo", "q5pRbXWNHHioRXP" ]; var result = "";
Tests:
Plus operator
for (var i = 0; i < stringArray.length; i++) { result = result + stringArray[i]; } result=result+".";
using concat function
for (var i = 0; i < stringArray.length; i++) { result = result.concat(stringArray[i]); } result = result.concat(".");
using template literals
for (var i = 0; i < stringArray.length; i++) { result = `${result}${stringArray[i]}`; } result = `${result}.`;
Plus equal operator
for (var i = 0; i < stringArray.length; i++) { result += stringArray[i]; } result+=".";
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Plus operator
using concat function
using template literals
Plus equal operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! The provided JSON represents a benchmark named "String concatenation-2021". This benchmark tests how different methods of string concatenation perform in JavaScript. **Tested options:** 1. **Plus operator (+)**: Concatenating strings using the plus operator. 2. **Using concat function**: Concatenating strings using the `concat()` method. 3. **Using template literals**: Using template literals to concatenate strings. 4. **Plus equal operator (=)**: Concatenating strings using the assignment operator. **Pros and cons of each approach:** 1. **Plus operator (+)**: * Pros: Simple, widely supported, and efficient for small strings. * Cons: Can be slow for large strings due to string creation and copying. 2. **Using concat function**: * Pros: Fast, as it avoids creating a new string object each time. * Cons: Less readable than other methods, requires the `concat()` method, which might not be available in all browsers or environments. 3. **Using template literals**: * Pros: Fast and efficient, as it uses a single string object creation. * Cons: Requires support for template literals (introduced in ECMAScript 2015), less readable than other methods. 4. **Plus equal operator (=)**: * Pros: Simple and widely supported, but not as efficient as other methods. * Cons: Can lead to unexpected behavior if used incorrectly. **Library/dependencies:** In this benchmark, the `concat()` method is used, which is a built-in JavaScript function. No external libraries or dependencies are required. **Special JS features/syntax:** The benchmark uses template literals, which were introduced in ECMAScript 2015 (ES6). This feature allows for more efficient string concatenation using the `${}` syntax. **Latest benchmark result:** The latest results show that: * Using `concat()` function is the fastest method. * Using template literals is close behind, but slower than `concat()`. * The plus operator (+) and plus equal operator (=) are the slowest methods. Keep in mind that these results may vary depending on the specific JavaScript engine, browser, or environment used.
Related benchmarks:
has vs includes vs indexOf
String COMPARE
array vs array filtering with includes
array vs array filtering with includes 2
Comments
Confirm delete:
Do you really want to delete benchmark?