Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
String concatenation vs array join Chrome 3
(version: 0)
Comparing performance of:
String concatentation vs Array join vs Array join (w/ push)
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var str = ""; var i; var sArr = [];
Tests:
String concatentation
str = ''; for (i = 1000; i > 0; i--) { str += "String concatenation. " + i; }
Array join
sArr = []; for (i = 1000; i > 0; i--) { sArr[i] = "String concatenation. " + i; } str = sArr.join("");
Array join (w/ push)
sArr = []; for (i = 1000; i > 0; i--) { sArr.push("String concatenation. " + i); } str = sArr.join("");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
String concatentation
Array join
Array join (w/ push)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
String concatentation
11523.9 Ops/sec
Array join
18889.7 Ops/sec
Array join (w/ push)
18535.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark. **What is being tested?** The benchmark measures the performance of two approaches to concatenate strings: 1. **String concatenation**: This involves using the `+` operator to concatenate strings in a loop (in this case, 1000 iterations). 2. **Array join**: This approach uses an array to store strings and then joins them together using the `join()` method. **Options compared** The benchmark compares three variants of the Array join approach: 1. **Basic Array join**: Uses `sArr.join("")` to concatenate the strings in the array. 2. **Array join with push**: Uses `push()` to add strings to the array and then uses `join()` to concatenate them. **Pros and Cons** Here are some pros and cons of each approach: * **String concatenation**: + Pros: Simple and easy to understand, no extra memory allocation required. + Cons: Can be slow due to the overhead of creating a new string object in each iteration. * **Basic Array join**: + Pros: Can be faster than string concatenation because it avoids the overhead of creating multiple string objects. + Cons: Requires an array to store all strings, which can lead to higher memory usage. * **Array join with push**: + Pros: Combines the benefits of basic array join and string concatenation (avoiding memory allocation). + Cons: Still requires some memory allocation for the array. **Other considerations** The benchmark does not consider other factors that might affect performance, such as: * Optimizations for modern browsers * Differences in browser engines or implementations * Impact of code organization or caching on performance **Library and syntax** There is no explicit library mentioned in the benchmark definition. However, the `join()` method is a built-in JavaScript method used to concatenate strings. No special JavaScript features or syntax are being tested in this benchmark. **Alternatives** If you want to explore other approaches to string concatenation or array join, consider: * Using `template literals` (introduced in ECMAScript 2015) for simple concatenation. * Utilizing `concat()` method on arrays for joining strings. * Investigating third-party libraries like Lodash for functional programming utilities. Note that these alternatives may not be relevant to the specific performance comparison being made here.
Related benchmarks:
String concatenation vs array join precise
String concatenation vs array join v6
string concat + join vs unshift + join
String concatenation vs array join Chrome
Comments
Confirm delete:
Do you really want to delete benchmark?