Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Split vs substring with concat
(version: 0)
References string parts to test hidden performance optimizations between the two implementations by not throwing away the results of the operation.
Comparing performance of:
Split and concat vs Substring and concat
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
Split and concat
const email = 'some.long.email.addr@example.org'; const [part1, part2] = email.split('@'); const joined = part1 + '@' + part2
Substring and concat
const email = 'some.long.email.addr@example.org'; const part1 = email.substring(0, email.indexOf('@')); const part2 = email.substring(email.indexOf('@') + 1); const joined = part1 + '@' + part2;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Split and concat
Substring and concat
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/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Split and concat
41514208.0 Ops/sec
Substring and concat
175403952.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark test cases. **Benchmark Purpose:** The primary purpose of this benchmark is to compare the performance of two approaches to extract the domain from an email address: 1. **Split**: Using the `split()` method with the '@' character as a separator to split the string into two parts. 2. **Substring**: Using the `substring()` method to extract specific parts of the string. **Options Comparison:** The benchmark tests these two approaches, which are fundamental JavaScript methods for string manipulation. Pros and Cons: * **Split()** + Pros: - Easy to read and understand - Fast, as it avoids creating intermediate strings - Works with most string types (e.g., numbers, dates) + Cons: - May not be the most efficient method for large strings or performance-critical applications * **Substring()** + Pros: - More flexible than split(), allowing for more complex extraction scenarios - Can be used to extract specific parts of a string without modifying the original string + Cons: - Creates intermediate strings, which can lead to performance issues with large inputs **Library and Special Features:** There are no external libraries used in this benchmark. No special JavaScript features or syntax are being tested; however, it's worth noting that some modern browsers may have additional features or optimizations for string manipulation methods like `split()` or `substring()`, such as support for Unicode characters or optimized implementations. **Alternatives:** If you needed to extract the domain from an email address, you might consider using other methods, such as: * Using a dedicated library or function specifically designed for parsing email addresses (e.g., the `parseEmail()` method in Node.js) * Utilizing regular expressions to extract specific parts of the string * Employing other string manipulation techniques, like using `indexOf()` and concatenation However, these alternatives might not be as straightforward or efficient as the original methods tested in this benchmark. In summary, the benchmark tests two fundamental JavaScript methods for string manipulation: `split()` and `substring()`. While `split()` is generally faster and more straightforward, `substring()` provides more flexibility but may create intermediate strings. The choice between these methods ultimately depends on the specific requirements of your application.
Related benchmarks:
String.Split and String.Match
String.split vs String.substring
match vs split multiple test string
Array split vs string substring - second position - destructure
Comments
Confirm delete:
Do you really want to delete benchmark?