Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Instly: String concat
(version: 0)
Comparing performance of:
String Concat vs Template Literals
Created:
7 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var gallery = 0;
Tests:
String Concat
var test = "<div class='embed-wrapper'><div class='embed-color-pill cat-"+gallery+"'></div><div class='embed'><table><tr><td colspan='2'><div><a class='embed-provider linkIgnore' href='https://exhentai.org/' target='_blank' rel='noreferrer'>ExHentai</a></div><div><a class='embed-title linkIgnore' href='https://exhentai.org/g/"+gallery+"/"+gallery+"/' target='_blank' rel='noreferrer'>"+gallery+"</a>"+(gallery ? " <span class='custom_warning'>(Expunged)</span>": "")+"</div></td></tr><tr><td><div><img class='image gallery_preview' src='"+gallery+"'></div></td><td><table class='gallery_info'><tr><td>Category:</td><td class='desc cat-"+gallery+"'>"+gallery+"</td></tr><tr><td>Rating:</td><td class='desc'>"+gallery+"</td></tr><tr><td>Images:</td><td class='desc'>"+gallery+"</td></tr><tr><td>Uploaded:</td><td class='desc'>"+new Date(gallery*1000).toLocaleString("en-GB")+"</td></tr><tr><td>Tags:</td><td class='tags'>"+gallery+"</td></tr><tr><td>Size:</td><td class='desc'>"+gallery+"</td></tr><tr><td>Torrent:</td><td class='desc'><a class='linkIgnore' href='https://exhentai.org/gallerytorrents.php?gid="+gallery+"&t="+gallery+"' target='_blank' rel='noreferrer'>Search</a></td></tr></table></td></tr></table></div></div>"
Template Literals
var test = `<div class='embed-wrapper'><div class='embed-color-pill cat-${gallery}'></div><div class='embed'><table><tr><td colspan='2'><div><a class='embed-provider linkIgnore' href='https://exhentai.org/' target='_blank' rel='noreferrer'>ExHentai</a></div><div><a class='embed-title linkIgnore' href='https://exhentai.org/g/${gallery}/${gallery}/' target='_blank' rel='noreferrer'>${gallery}</a>"+(gallery ? " <span class='custom_warning'>(Expunged)</span>": "")+"</div></td></tr><tr><td><div><img class='image gallery_preview' src='${gallery}'></div></td><td><table class='gallery_info'><tr><td>Category:</td><td class='desc cat-${gallery}'>${gallery}</td></tr><tr><td>Rating:</td><td class='desc'>${gallery}</td></tr><tr><td>Images:</td><td class='desc'>${gallery}</td></tr><tr><td>Uploaded:</td><td class='desc'>"+new Date(gallery*1000).toLocaleString("en-GB")+"</td></tr><tr><td>Tags:</td><td class='tags'>"+gallery+"</td></tr><tr><td>Size:</td><td class='desc'>"+gallery+"</td></tr><tr><td>Torrent:</td><td class='desc'><a class='linkIgnore' href='https://exhentai.org/gallerytorrents.php?gid=${gallery}&t=${gallery}' target='_blank' rel='noreferrer'>Search</a></td></tr></table></td></tr></table></div></div>`
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
String Concat
Template Literals
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):
I'll break down the provided benchmark definition and test cases to explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark definition is a JSON object that defines two microbenchmarks: 1. "Instly: String concat" 2. "Template Literals" Both benchmarks involve string concatenation or templating, but with different approaches. **"Instly: String Concat" Benchmark** This benchmark uses the following script preparation code: ```javascript var gallery = 0; ``` The benchmark definition itself is a simple JavaScript expression that concatenates strings using the `+` operator: ```javascript var test = "..."; // long string literal containing HTML and variables ``` **Pros:** * Simple and straightforward implementation * Easy to understand and maintain **Cons:** * Uses the old-fashioned `+` operator for string concatenation, which can be slow * May not work well with large strings or complex expressions **"Template Literals" Benchmark** This benchmark uses a template literal syntax introduced in ECMAScript 2015: ```javascript var test = `<div class='embed-wrapper'><div class='embed-color-pill cat-${gallery}'></div><div class='embed'><table><tr><td colspan='2'><div><a class='embed-provider linkIgnore' href='https://exhentai.org/' target='_blank' rel='noreferrer'>ExHentai</a></div><div><a class='embed-title linkIgnore' href='https://exhentai.org/g/${gallery}/${gallery}/' target='_blank' rel='noreferrer'>${gallery}</a>\"+(gallery ? \" <span class='custom_warning'>(Expunged)</span>\": \"\")+\"</div></td></tr><tr><td><div><img class='image gallery_preview' src='${gallery}'></div></td><td><table class='gallery_info'><tr><td>Category:</td><td class='desc cat-${gallery}'>${gallery}</td></tr><tr><td>Rating:</td><td class='desc'>${gallery}</td></tr><tr><td>Images:</td><td class='desc'>${gallery}</td></tr><tr><td>Uploaded:</td><td class='desc'>\"+new Date(gallery*1000).toLocaleString(\"en-GB\")+\"</td></tr><tr><td>Tags:</td><td class='tags'>\"+gallery+\"</td></tr><tr><td>Size:</td><td class='desc'>\"+gallery+\"</td></tr><tr><td>Torrent:</td><td class='desc'><a class='linkIgnore' href='https://exhentai.org/gallerytorrents.php?gid=${gallery}&t=${gallery}' target='_blank' rel='noreferrer'>Search</a></td></tr></table></td></tr></table></div></div>`; ``` **Pros:** * Uses a more modern and efficient syntax for string concatenation * Can handle large strings and complex expressions without performance issues **Cons:** * Requires ECMAScript 2015 or later to run * May be less familiar to some developers due to its non-standard syntax **Comparison** The two benchmarks compare the performance of using traditional string concatenation (`+` operator) versus template literals (introduced in ECMAScript 2015). The benchmark results show that template literals outperform traditional string concatenation. **Other Alternatives** If you prefer not to use template literals, other alternatives for efficient string concatenation include: * Using the `String.prototype.format()` method or `lodash.escape()` * Utilizing a library like underscore.js or moment.js * Employing lazy loading or caching techniques Keep in mind that the choice of implementation ultimately depends on your specific requirements, team familiarity, and performance constraints.
Related benchmarks:
concatvsnoconcat
array_concat_sprad
Issou by Ruskie
ad1235
concat vs plus string
Comments
Confirm delete:
Do you really want to delete benchmark?