Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Concat vs plus sign string
(version: 1)
Comparing performance of:
Concat vs + sign
Created:
7 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const image = 'https://www.dell.com/images/global/navigation/navbar/delllogo.svg'; const prodname = 'Latitude'; const viewItemUrl = 'https://www.dell.com/en-us/shop/computing/latitude'; const rewardsTotalValue = '$1357.85'; const display = '$1557.85'; const a = 'goToCartElClass'; const r = 'rewardsTotalValue'; const isConfigurable = 'isConfigurable'; const description = 'lorem ipsum dolor sit amet consectetur adipiscing elit';
Tests:
Concat
const html = '\n <div class="tnt-dell-rewards-carousel-body-item">\n <div class="tnt-dell-rewards-carousel-body-item-image">\n <img src="'.concat(image,'" alt="').concat(prodname,'">\n </div>\n <div class="tnt-dell-rewards-carousel-body-item-info">\n <p class="tnt-dell-rewards-item-name"><a href="').concat(viewItemUrl,'" title="').concat(prodname,'">').concat(prodname,'</a></p>\n <p class="tnt-dell-rewards-item-value">after applying <b>').concat(rewardsTotalValue,'</b> Rewards when paying in checkout</p>\n </div>\n <div class="tnt-dell-rewards-carousel-body-item-price">\n <s>').concat(display,"</s>\n <b>").concat(a,'</b>\n </div>\n <div class="tnt-dell-rewards-carousel-body-item-buttons">\n <a href="//www.dell.com/purchase/cart/en-ca" class="').concat(r,'" title="Go to Cart">Go to Cart</a>\n <a href="').concat(viewItemUrl,'" class="tnt-dell-rewards-button-secondary tnt-dell-rewards-button-configurable-').concat(isConfigurable,'" title="Customize">Customize the ').concat(description&&description.slice(0,-1),"</a>\n </div>\n </div>\n "); document.body.insertAdjacentHTML('afterbegin', html);
+ sign
const html = '\n <div class="tnt-dell-rewards-carousel-body-item">\n <div class="tnt-dell-rewards-carousel-body-item-image">\n <img src="'+ image +'" alt="' + prodname +'">\n </div>\n <div class="tnt-dell-rewards-carousel-body-item-info">\n <p class="tnt-dell-rewards-item-name"><a href="'+viewItemUrl+'" title="'+prodname+'">'+prodname+'</a></p>\n <p class="tnt-dell-rewards-item-value">after applying <b>'+rewardsTotalValue+'</b> Rewards when paying in checkout</p>\n </div>\n <div class="tnt-dell-rewards-carousel-body-item-price">\n <s>'+display+"</s>\n <b>"+a+'</b>\n </div>\n <div class="tnt-dell-rewards-carousel-body-item-buttons">\n <a href="//www.dell.com/purchase/cart/en-ca" class="'+r+'" title="Go to Cart">Go to Cart</a>\n <a href="'+viewItemUrl+'" class="tnt-dell-rewards-button-secondary tnt-dell-rewards-button-configurable-'+isConfigurable+'" title="Customize">Customize the '+description&&description.slice(0,-1)+'</a>\n </div>\n </div>\n '; document.body.insertAdjacentHTML('afterbegin', html);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Concat
+ sign
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Concat
38238.1 Ops/sec
+ sign
284984.7 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated 7 months ago):
The benchmark defined in the provided JSON tests the performance of two different methods for constructing and manipulating strings in JavaScript: using the `concat()` method and the `+` (plus sign) operator. ### Options Compared 1. **String Concatenation using `concat()` Method**: - **Test Case**: ```javascript const html = '\\n <div class="tnt-dell-rewards-carousel-body-item">\\n ... img src="'.concat(image,'\" alt=\"').concat(prodname,'\">\\n ...</div>\\n "); ``` 2. **String Concatenation using `+` (Plus Sign) Operator**: - **Test Case**: ```javascript const html = '\\n <div class="tnt-dell-rewards-carousel-body-item">\\n ... img src="'+ image +'" alt="'+ prodname +'">\\n ...</div>\\n '; ``` ### Performance Results According to the latest benchmark results: - The `+` operator achieved **284984.69 executions per second**. - The `concat()` method achieved **38238.09 executions per second**. ### Pros and Cons **Using `concat()` method:** - **Pros**: - More explicit and can be easier to read in some contexts, especially for multi-part concatenations. - Can be chained to concatenate multiple strings in a single expression. - **Cons**: - Generally slower than the `+` operator in modern JavaScript engines, as indicated by the benchmark results. - Slightly less common, which might lead to less familiarity among developers. **Using `+` (Plus Sign) Operator:** - **Pros**: - Typically faster and preferred in performance-sensitive situations, as shown by the benchmark results. - More idiomatic for concatenating strings in JavaScript; most developers are familiar with its usage. - **Cons**: - More prone to errors in complex statements when not carefully managed. - Might become less readable when concatenating many strings with different variables, especially if newlines or escape characters are required. ### Other Considerations In JavaScript, string concatenation has evolved, and modern JavaScript engines are highly optimized for the `+` operator. While using `concat()` may still have its use cases, the `+` operator is often favored for its performance and readability. JavaScript also supports template literals (using backticks `` ` ``) which allow for a cleaner, more readable way to do multi-line strings and string interpolation, avoiding concatenation altogether: ```javascript const html = ` <div class="tnt-dell-rewards-carousel-body-item"> <div class="tnt-dell-rewards-carousel-body-item-image"> <img src="${image}" alt="${prodname}"> </div> ... </div> `; ``` Template literals introduce features such as: - Multi-line strings. - Variable interpolation without explicit concatenation. - Cleaner syntax, improving maintainability. Overall, the choice between these methods depends on the specific requirements of your application, the readability of the code, and the performance needs of your string manipulations. For common use cases, it’s usually best to use the `+` operator or, when appropriate, template literals to keep the code clean and efficient.
Related benchmarks:
if cond
Array Exists vs If...else
switch-range vs if-immediate
ghgfhfdgdfgfdgf
if vs else
Test if else 2
Test if else 2bis
Test if else 3
Concat vs plus sign string vs string literals
Comments
Confirm delete:
Do you really want to delete benchmark?